Skip to content

Commit

Permalink
chore: prettier & fix eslint (#2444)
Browse files Browse the repository at this point in the history
* prettier

* fix eslint

* prettier

* prettier

* lint

* add prettier eslint plugin

* config eslint ignore & global require
  • Loading branch information
imhele authored and sorrycc committed May 21, 2019
1 parent cdf309f commit 5f85fe3
Show file tree
Hide file tree
Showing 175 changed files with 706 additions and 1,582 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ node_modules/
lib/
dist/
template/
templates/
fixtures/
website/
examples/
bin/
*.d.ts
*.min.js
packages/umi-build-dev/src/plugins/commands/ui/plugins/blocks
23 changes: 17 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
{
"parser": "babel-eslint",
"extends": "airbnb",
"plugins": ["prettier"],
"extends": ["airbnb", "prettier"],
"env": {
"browser": true,
"jest": true
},
"globals": {
"__UMI_BIGFISH_COMPAT": true,
"__UMI_HTML_SUFFIX": true
},
"rules": {
"jsx-a11y/href-no-hash": [0],
"jsx-a11y/click-events-have-key-events": [0],
"jsx-a11y/anchor-is-valid": [ "error", {
"components": [ "Link" ],
"specialLink": [ "to" ]
}],
"jsx-a11y/anchor-is-valid": [
"error",
{
"components": ["Link"],
"specialLink": ["to"]
}
],
"generator-star-spacing": [0],
"consistent-return": [0],
"radix": [1],
"react/react-in-jsx-scope": [0],
"react/forbid-prop-types": [0],
"react/jsx-filename-extension": [1, { "extensions": [".js"] }],
"global-require": [1],
"global-require": [0],
"import/prefer-default-export": [0],
"react/jsx-no-bind": [0],
"react/prop-types": [0],
"react/prefer-stateless-function": [0],
"react/jsx-one-expression-per-line": [0],
"react/button-has-type": [0],
"no-else-return": [0],
"no-restricted-syntax": [0],
"import/no-extraneous-dependencies": [0],
Expand Down
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"trailingComma": "all",
"singleQuote": true
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"dva": "2.4.1",
"eslint": "5.10.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "^4.2.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "7.11.1",
"form-data": "^2.3.3",
"got": "9.3.2",
Expand Down
4 changes: 1 addition & 3 deletions packages/af-webpack/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export default function build(opts = {}) {
assert(webpackConfig, 'webpackConfig should be supplied.');
assert(isPlainObject(webpackConfig), 'webpackConfig should be plain object.');

debug(
`Clean output path ${webpackConfig.output.path.replace(`${cwd}/`, '')}`,
);
debug(`Clean output path ${webpackConfig.output.path.replace(`${cwd}/`, '')}`);
rimraf.sync(webpackConfig.output.path);

debug('build start');
Expand Down
5 changes: 1 addition & 4 deletions packages/af-webpack/src/choosePort.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export default function choosePort(defaultPort) {
}),
err => {
throw new Error(
chalk.red(
`Could not find an open port.\nNetwork error message: ${err.message ||
err}\n`,
),
chalk.red(`Could not find an open port.\nNetwork error message: ${err.message || err}\n`),
);
},
);
Expand Down
4 changes: 1 addition & 3 deletions packages/af-webpack/src/clearConsole.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export default function() {
const { CLEAR_CONSOLE = 'none' } = process.env;
if (CLEAR_CONSOLE !== 'none') {
process.stdout.write(
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H',
);
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
}
}
8 changes: 2 additions & 6 deletions packages/af-webpack/src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ const isInteractive = process.stdout.isTTY;
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 8000;
const HOST = process.env.HOST || '0.0.0.0';
const PROTOCOL = process.env.HTTPS ? 'https' : 'http';
const CERT =
process.env.HTTPS && process.env.CERT
? fs.readFileSync(process.env.CERT)
: '';
const KEY =
process.env.HTTPS && process.env.KEY ? fs.readFileSync(process.env.KEY) : '';
const CERT = process.env.HTTPS && process.env.CERT ? fs.readFileSync(process.env.CERT) : '';
const KEY = process.env.HTTPS && process.env.KEY ? fs.readFileSync(process.env.KEY) : '';
const noop = () => {};

process.env.NODE_ENV = 'development';
Expand Down
8 changes: 3 additions & 5 deletions packages/af-webpack/src/fork.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { fork } from 'child_process';
import send, { RESTART } from './send';

let usedPorts = [];
const usedPorts = [];

export default function start(scriptPath) {
const execArgv = process.execArgv.slice(0);
const inspectArgvIndex = execArgv.findIndex(argv =>
argv.includes('--inspect-brk'),
);
const inspectArgvIndex = execArgv.findIndex(argv => argv.includes('--inspect-brk'));

if (inspectArgvIndex > -1) {
const inspectArgv = execArgv[inspectArgvIndex];
Expand All @@ -22,7 +20,7 @@ export default function start(scriptPath) {
port = 9230; // node default inspect port plus 1.
}
if (usedPorts.includes(port)) {
port++;
port += 1;
}
usedPorts.push(port);
return `--inspect-brk=${port}`;
Expand Down
15 changes: 3 additions & 12 deletions packages/af-webpack/src/formatWebpackMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,14 @@ function formatMessage(message, isError) {

// Cleans up syntax error messages.
if (lines[1].indexOf('Module build failed: ') === 0) {
lines[1] = lines[1].replace(
'Module build failed: SyntaxError:',
friendlySyntaxErrorLabel,
);
lines[1] = lines[1].replace('Module build failed: SyntaxError:', friendlySyntaxErrorLabel);
}

// Clean up export errors.
// TODO: we should really send a PR to Webpack for this.
const exportError = /\s*(.+?)\s*(")?export '(.+?)' was not found in '(.+?)'/;
if (lines[1].match(exportError)) {
lines[1] = lines[1].replace(
exportError,
"$1 '$4' does not contain an export named '$3'.",
);
lines[1] = lines[1].replace(exportError, "$1 '$4' does not contain an export named '$3'.");
}

// Reassemble the message.
Expand All @@ -89,10 +83,7 @@ function formatMessage(message, isError) {
// exception of stacks containing `webpack:` because they're normally
// from user code generated by WebPack. For more information see
// https://github.com/facebookincubator/create-react-app/pull/1050
message = message.replace(
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
'',
); // at ... ...:x:y
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y

return message.trim();
}
Expand Down
3 changes: 0 additions & 3 deletions packages/af-webpack/src/getConfig/dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { existsSync, writeFileSync } from 'fs';
import { join } from 'path';

export default function(webpackConfig, opts) {
webpackConfig
.devtool(opts.devtool || 'cheap-module-source-map')
Expand Down
2 changes: 2 additions & 0 deletions packages/af-webpack/src/getConfig/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function(opts) {

// entry
if (opts.entry) {
// eslint-disable-next-line guard-for-in
for (const key in opts.entry) {
const entry = webpackConfig.entry(key);
makeArray(opts.entry[key]).forEach(file => {
Expand Down Expand Up @@ -65,6 +66,7 @@ export default function(opts) {
]);

if (opts.alias) {
// eslint-disable-next-line guard-for-in
for (const key in opts.alias) {
webpackConfig.resolve.alias.set(key, opts.alias[key]);
}
Expand Down
8 changes: 2 additions & 6 deletions packages/af-webpack/src/getConfig/resolveDefine.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/* eslint-disable guard-for-in */
const prefixRE = /^UMI_APP_/;

export default function(opts) {
const env = {};
Object.keys(process.env).forEach(key => {
if (
prefixRE.test(key) ||
key === 'NODE_ENV' ||
key === 'HMR' ||
key === 'SOCKET_SERVER'
) {
if (prefixRE.test(key) || key === 'NODE_ENV' || key === 'HMR' || key === 'SOCKET_SERVER') {
env[key] = process.env[key];
}
});
Expand Down
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'alias',
validate(val) {
assert(
isPlainObject(val),
`The alias config must be Plain Object, but got ${val}`,
);
assert(isPlainObject(val), `The alias config must be Plain Object, but got ${val}`);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'autoprefixer',
validate(val) {
assert(
isPlainObject(val),
`The autoprefixer config must be Plain Object, but got ${val}`,
);
assert(isPlainObject(val), `The autoprefixer config must be Plain Object, but got ${val}`);
},
};
}
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'babel',
validate(val) {
assert(
isPlainObject(val),
`The babel config must be Plain Object, but got ${val}`,
);
assert(isPlainObject(val), `The babel config must be Plain Object, but got ${val}`);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'browserslist',
validate(val) {
assert(
Array.isArray(val),
`The browserslist config must be Array, but got ${val}`,
);
assert(Array.isArray(val), `The browserslist config must be Array, but got ${val}`);
},
};
}
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/chainConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'chainConfig',
validate(val) {
assert(
typeof val === 'function',
`The chainConfig config must be Function, but got ${val}`,
);
assert(typeof val === 'function', `The chainConfig config must be Function, but got ${val}`);
},
};
}
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'copy',
validate(val) {
assert(
Array.isArray(val),
`The copy config must be Array, but got ${val}`,
);
assert(Array.isArray(val), `The copy config must be Array, but got ${val}`);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'cssModulesExcludes',
validate(val) {
assert(
Array.isArray(val),
`The cssModulesExcludes config must be Array, but got ${val}`,
);
assert(Array.isArray(val), `The cssModulesExcludes config must be Array, but got ${val}`);
val.forEach(file => {
const ext = extname(file).toLowerCase();
assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'cssPublicPath',
validate(val) {
assert(
typeof val === 'string',
`The cssPublicPath config must be String, but got ${val}`,
);
assert(typeof val === 'string', `The cssPublicPath config must be String, but got ${val}`);
},
};
}
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/cssnano.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'cssnano',
validate(val) {
assert(
isPlainObject(val),
`The cssnano config must be Plain Object, but got ${val}`,
);
assert(isPlainObject(val), `The cssnano config must be Plain Object, but got ${val}`);
},
};
}
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'define',
validate(val) {
assert(
isPlainObject(val),
`The define config must be Plain Object, but got ${val}`,
);
assert(isPlainObject(val), `The define config must be Plain Object, but got ${val}`);
},
};
}
1 change: 1 addition & 0 deletions packages/af-webpack/src/getUserConfig/configs/devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default function() {
return {
name: 'devServer',
onChange() {
// eslint-disable-next-line no-undef
api.service.restart(/* why */ 'Config devServer Changed');
},
};
Expand Down
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/devtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'devtool',
validate(val) {
assert(
typeof val === 'string',
`The devtool config must be String, but got ${val}`,
);
assert(typeof val === 'string', `The devtool config must be String, but got ${val}`);
},
};
}
5 changes: 1 addition & 4 deletions packages/af-webpack/src/getUserConfig/configs/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default function() {
return {
name: 'env',
validate(val) {
assert(
isPlainObject(val),
`The env config must be Plain Object, but got ${val}`,
);
assert(isPlainObject(val), `The env config must be Plain Object, but got ${val}`);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'extraBabelIncludes',
validate(val) {
assert(
Array.isArray(val),
`The extraBabelIncludes config must be Array, but got ${val}`,
);
assert(Array.isArray(val), `The extraBabelIncludes config must be Array, but got ${val}`);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export default function() {
return {
name: 'extraBabelPlugins',
validate(val) {
assert(
Array.isArray(val),
`The extraBabelPlugins config must be Array, but got ${val}`,
);
assert(Array.isArray(val), `The extraBabelPlugins config must be Array, but got ${val}`);
},
};
}

0 comments on commit 5f85fe3

Please sign in to comment.