From 7a6485d1ab63a6eb5c2fbcd7a6ce88f02520c4a0 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Thu, 14 Apr 2016 11:27:31 +0800 Subject: [PATCH] chore: update lint scripts --- package.json | 4 ++-- scripts/build-common.js | 3 --- scripts/build-demos-list.js | 6 ++---- scripts/build-website.js | 2 -- scripts/deploy.js | 8 ++++---- scripts/install.js | 18 +++++++++--------- scripts/prenpm.js | 12 ++++++------ scripts/utils.js | 7 ++++--- webpack.config.js | 6 +++--- 9 files changed, 30 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 0d4d6524f44a..d0f1fa00fc72 100644 --- a/package.json +++ b/package.json @@ -133,10 +133,10 @@ "deploy": "rm -rf node_modules && node scripts/install.js && npm run just-deploy", "just-deploy": "npm run site && node scripts/deploy.js", "lint": "npm run srclint && npm run demolint && npm run lesshint", - "srclint": "ANTD=SRC eslint components test site index.js --ext '.js,.jsx'", + "srclint": "ANTD=SRC eslint components test site scripts ./*.js --ext '.js,.jsx'", "demolint": "ANTD=DEMO eslint components/*/demo/*.md --ext '.md'", "lesshint": "lesshint style/ -e 'style/+(core|mixins)/+(base|iconfont|normalize|layouts|compatibility|grid).less'", - "eslint-fix": "eslint --fix components test site index.js --ext '.js,.jsx' && eslint-tinker ./components/*/demo/*.md", + "eslint-fix": "eslint --fix components test site scripts ./*.js --ext '.js,.jsx' && eslint-tinker ./components/*/demo/*.md", "test": "npm run lint && atool-build && npm run jest", "jest": "jest", "pub": "sh ./scripts/publish.sh", diff --git a/scripts/build-common.js b/scripts/build-common.js index 6da601a227d1..2007604cde3c 100644 --- a/scripts/build-common.js +++ b/scripts/build-common.js @@ -1,8 +1,5 @@ -'use strict'; - const fs = require('fs'); const path = require('path'); -const R = require('ramda'); const utils = require('./utils'); module.exports = function buildCommon(dirs, outputFile) { diff --git a/scripts/build-demos-list.js b/scripts/build-demos-list.js index c0b41d80fd62..66256e82fafc 100644 --- a/scripts/build-demos-list.js +++ b/scripts/build-demos-list.js @@ -1,5 +1,3 @@ -'use strict'; - const fs = require('fs'); const path = require('path'); const R = require('ramda'); @@ -23,10 +21,10 @@ module.exports = function buildDemosList(dirs, outputPath) { Object.keys(groupedDemos).forEach((key) => { content += `\n '${key}': [`; groupedDemos[key].forEach((fileName) => { - const requirePath = path.relative(path.dirname(outputPath), fileName) + const requirePath = path.relative(path.dirname(outputPath), fileName); content += `\n require('${requirePath}'),`; }); - content += '\n ],' + content += '\n ],'; }); content += '\n};\n'; diff --git a/scripts/build-website.js b/scripts/build-website.js index fbfedb794a2e..90dd6937530e 100755 --- a/scripts/build-website.js +++ b/scripts/build-website.js @@ -1,7 +1,5 @@ #! /usr/bin/env node -'use strict'; - // Ensure that data directory exist. require('mkdirp').sync('./_data'); diff --git a/scripts/deploy.js b/scripts/deploy.js index f1fb90597436..283f69f14d42 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -1,11 +1,11 @@ -var ghPages = require('gh-pages'); -var path = require('path'); +const ghPages = require('gh-pages'); +const path = require('path'); ghPages.publish(path.join(process.cwd(), '_site'), { depth: 1, - logger: function (message) { + logger(message) { console.log(message); } -}, function (err) { +}, (err) => { if (err) { throw err; } diff --git a/scripts/install.js b/scripts/install.js index 847ed51d3e7c..913975d2569b 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -1,23 +1,23 @@ function runCmd(cmd, args, fn) { args = args || []; - var runner = require('child_process').spawn(cmd, args, { + const runner = require('child_process').spawn(cmd, args, { // keep color - stdio: "inherit" + stdio: 'inherit' }); - runner.on('close', function (code) { + runner.on('close', (code) => { if (fn) { fn(code); } }); } -runCmd('which', ['tnpm'], function (code) { - var npm = 'npm'; +runCmd('which', ['tnpm'], (code) => { + let npm = 'npm'; if (!code) { npm = 'tnpm'; } - console.log(npm + ' installing'); - runCmd(npm, ['install'], function () { - console.log(npm + ' install end'); + console.log(`${npm} installing`); + runCmd(npm, ['install'], () => { + console.log(`${npm} install end`); }); -}); \ No newline at end of file +}); diff --git a/scripts/prenpm.js b/scripts/prenpm.js index ce17cdae54e7..419197f9ca05 100644 --- a/scripts/prenpm.js +++ b/scripts/prenpm.js @@ -1,11 +1,11 @@ -var fs = require('fs'); -var cwd = process.cwd(); -var path = require('path'); -var originalIndex = fs.readFileSync(path.join(cwd, 'lib/index.js'), 'utf-8'); -var newIndex = originalIndex +const fs = require('fs'); +const cwd = process.cwd(); +const path = require('path'); +const originalIndex = fs.readFileSync(path.join(cwd, 'lib/index.js'), 'utf-8'); +const newIndex = originalIndex .replace(/\/components\//g, '/'); fs.writeFileSync(path.join(cwd, 'lib/index.js'), newIndex, 'utf-8'); -var antdCss = path.join(cwd, 'dist/antd.css'); +const antdCss = path.join(cwd, 'dist/antd.css'); fs.createReadStream(antdCss) .pipe(fs.createWriteStream(path.join(cwd, 'lib/index.css'))); console.log('prenpm done'); diff --git a/scripts/utils.js b/scripts/utils.js index 50aa055ec87a..8b1b70649d1f 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -1,9 +1,9 @@ -'use strict'; - const fs = require('fs'); const path = require('path'); const R = require('ramda'); +function noop() {} + const isMDFile = R.compose(R.equals('.md'), path.extname); exports.findMDFile = function findMDFile(fileName, shallow) { const filePaths = Array.isArray(fileName) ? fileName : [fileName]; @@ -19,7 +19,7 @@ exports.findMDFile = function findMDFile(fileName, shallow) { let hasIndexFile = false; try { hasIndexFile = fs.statSync(indexFile).isFile(); - } catch (e) {} + } catch (e) { noop(); } if (shallow && hasIndexFile) { mds.push(indexFile); @@ -34,6 +34,7 @@ exports.findMDFile = function findMDFile(fileName, shallow) { return mds; }; +/* eslint prefer-template: 0 */ exports.stringify = function stringify(data, d) { const depth = d || 1; const indent = ' '.repeat(depth); diff --git a/webpack.config.js b/webpack.config.js index 005aecb0e763..0de80b650e98 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,6 @@ const webpack = require('atool-build/lib/webpack'); -module.exports = function(webpackConfig) { +module.exports = function (webpackConfig) { // remove common.js webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => { return !(plugin instanceof webpack.optimize.CommonsChunkPlugin); @@ -38,7 +38,7 @@ module.exports = function(webpackConfig) { webpackConfig.module.loaders.push({ test: /\.md$/, exclude: [/node_modules/, componentRegExp], - loader: `babel!antd-md`, + loader: 'babel!antd-md', }); } } @@ -49,7 +49,7 @@ module.exports = function(webpackConfig) { 'antd.min': entry, }; webpackConfig.externals = { - 'react': { + react: { root: 'React', commonjs2: 'react', commonjs: 'react',