From 1b886ee3424e7761745d608324a301dc2998b928 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 24 Aug 2018 16:57:16 +0200 Subject: [PATCH] improve prettier and lint config and performance --- .editorconfig | 4 - .eslintrc.js | 45 +++--- .prettierignore | 18 +-- .prettierrc.js | 10 +- package.json | 4 +- schemas/WebpackOptions.json | 132 ++++-------------- schemas/plugins/BannerPlugin.json | 4 +- schemas/plugins/DllPlugin.json | 4 +- schemas/plugins/DllReferencePlugin.json | 13 +- schemas/plugins/HashedModuleIdsPlugin.json | 6 +- schemas/plugins/SourceMapDevToolPlugin.json | 10 +- .../plugins/optimize/MinChunkSizePlugin.json | 4 +- test/Schemas.lint.js | 6 - tsconfig.json | 28 ++-- 14 files changed, 89 insertions(+), 199 deletions(-) diff --git a/.editorconfig b/.editorconfig index 451371612..2bd8cf9e8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,10 +8,6 @@ trim_trailing_whitespace = true insert_final_newline = true max_line_length = 80 -[.prettierrc] -indent_style = space -indent_size = 2 - [*.{yml,yaml,json}] indent_style = space indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js index e4a7a3e86..37b4be6f4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,11 @@ module.exports = { root: true, plugins: ["prettier", "node", "jest"], - extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"], + extends: [ + "eslint:recommended", + "plugin:node/recommended", + "plugin:prettier/recommended" + ], env: { node: true, es6: true @@ -16,8 +20,8 @@ module.exports = { "no-template-curly-in-string": "error", "no-caller": "error", "no-control-regex": "off", - "yoda": "error", - "eqeqeq": "error", + yoda: "error", + eqeqeq: "error", "global-require": "off", "brace-style": "error", "eol-last": "error", @@ -27,23 +31,26 @@ module.exports = { "no-unused-vars": ["error", { args: "none" }], "no-unsafe-negation": "error", "no-loop-func": "warn", - "indent": "off", + indent: "off", "no-console": "off", - "valid-jsdoc": ["error", { - "prefer": { - "return": "returns", - "prop": "property", - "memberof": "DONTUSE", - "class": "DONTUSE", - "inheritdoc": "DONTUSE", - "description": "DONTUSE", - "readonly": "DONTUSE" - }, - "preferType": { - "*": "any" - }, - "requireReturnType": true - }], + "valid-jsdoc": [ + "error", + { + prefer: { + return: "returns", + prop: "property", + memberof: "DONTUSE", + class: "DONTUSE", + inheritdoc: "DONTUSE", + description: "DONTUSE", + readonly: "DONTUSE" + }, + preferType: { + "*": "any" + }, + requireReturnType: true + } + ], "node/no-unsupported-features": "error", "node/no-deprecated-api": "error", "node/no-missing-import": "error", diff --git a/.prettierignore b/.prettierignore index cb7d2b338..bdf38e4bc 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,16 +1,8 @@ -# Ignore all paths. -**/*.* - -# Enable prettier for the following paths. -!*.{ts,js,json} -!setup/**/*.js -!lib/**/*.js -!bin/*.js -!hot/*.js -!buildin/*.js -!benchmark/**/*.js +# Ignore test fixtures +test !test/*.js -!tooling/*.js !test/**/webpack.config.js + +# Ignore example fixtures +examples !examples/**/webpack.config.js -!schemas/**/*.js diff --git a/.prettierrc.js b/.prettierrc.js index 03b9da1ba..cc7e3b513 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,5 +1,13 @@ module.exports = { printWidth: 80, useTabs: true, - tabWidth: 2 + tabWidth: 2, + overrides: [ + { + files: "*.json", + options: { + useTabs: false + } + } + ] }; diff --git a/package.json b/package.json index 05b595329..3b46b09a2 100644 --- a/package.json +++ b/package.json @@ -120,10 +120,10 @@ "pretest": "yarn lint", "prelint": "yarn setup", "lint": "yarn code-lint && yarn schema-lint && yarn type-lint", - "code-lint": "eslint --cache setup lib bin hot buildin benchmark tooling \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", + "code-lint": "eslint --cache \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.js\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", "type-lint": "tsc --pretty", "fix": "yarn code-lint --fix", - "pretty": "prettier --write \"*.{ts,js,json}\" \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"benchmark/**/*.js\" \"tooling/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", + "pretty": "prettier --loglevel warn --write \"*.{ts,js,json}\" \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.{js,json}\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", "schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", "cover": "yarn cover:init && yarn cover:all && yarn cover:report", diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index bc2c3ff58..015131961 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -11,9 +11,7 @@ } }, "additionalProperties": true, - "required": [ - "apply" - ] + "required": ["apply"] }, "common.pluginObject": { "description": "Plugin instance", @@ -25,9 +23,7 @@ } }, "additionalProperties": true, - "required": [ - "apply" - ] + "required": ["apply"] }, "common.arrayOfStringOrStringArrayValues": { "items": { @@ -339,19 +335,11 @@ }, "crossOriginLoading": { "description": "This option enables cross-origin loading of chunks.", - "enum": [ - false, - "anonymous", - "use-credentials" - ] + "enum": [false, "anonymous", "use-credentials"] }, "jsonpScriptType": { "description": "This option enables loading async chunks via a custom script type, such as script type=\"module\"", - "enum": [ - false, - "text/javascript", - "module" - ] + "enum": [false, "text/javascript", "module"] }, "chunkLoadTimeout": { "description": "Number of milliseconds before chunk request expires", @@ -837,10 +825,7 @@ "properties": { "enforce": { "description": "Enforce this rule as pre or post step", - "enum": [ - "pre", - "post" - ] + "enum": ["pre", "post"] }, "exclude": { "description": "Shortcut for resource.exclude", @@ -1114,11 +1099,7 @@ "properties": { "mode": { "description": "Enable production optimizations or development hints.", - "enum": [ - "development", - "production", - "none" - ] + "enum": ["development", "production", "none"] }, "amd": { "description": "Set the value of `require.amd` and `define.amd`." @@ -1164,9 +1145,7 @@ "type": "string" }, { - "enum": [ - false - ] + "enum": [false] } ] }, @@ -1206,52 +1185,29 @@ "description": "Include polyfills or mocks for various node stuff.", "anyOf": [ { - "enum": [ - false - ] + "enum": [false] }, { "additionalProperties": { "description": "Include a polyfill for the node.js module", - "enum": [ - false, - true, - "mock", - "empty" - ] + "enum": [false, true, "mock", "empty"] }, "properties": { "Buffer": { "description": "Include a polyfill for the 'Buffer' variable", - "enum": [ - false, - true, - "mock" - ] + "enum": [false, true, "mock"] }, "__dirname": { "description": "Include a polyfill for the '__dirname' variable", - "enum": [ - false, - true, - "mock" - ] + "enum": [false, true, "mock"] }, "__filename": { "description": "Include a polyfill for the '__filename' variable", - "enum": [ - false, - true, - "mock" - ] + "enum": [false, true, "mock"] }, "console": { "description": "Include a polyfill for the 'console' variable", - "enum": [ - false, - true, - "mock" - ] + "enum": [false, true, "mock"] }, "global": { "description": "Include a polyfill for the 'global' variable", @@ -1259,11 +1215,7 @@ }, "process": { "description": "Include a polyfill for the 'process' variable", - "enum": [ - false, - true, - "mock" - ] + "enum": [false, true, "mock"] } }, "type": "object" @@ -1323,9 +1275,7 @@ "description": "Optimize duplication and caching by splitting chunks by shared modules and cache group", "oneOf": [ { - "enum": [ - false - ] + "enum": [false] }, { "type": "object", @@ -1335,11 +1285,7 @@ "description": "Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML)", "oneOf": [ { - "enum": [ - "initial", - "async", - "all" - ] + "enum": ["initial", "async", "all"] }, { "instanceof": "Function" @@ -1428,9 +1374,7 @@ "description": "Configuration for a cache group", "anyOf": [ { - "enum": [ - false - ] + "enum": [false] }, { "instanceof": "Function" @@ -1463,11 +1407,7 @@ "description": "Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML)", "oneOf": [ { - "enum": [ - "initial", - "async", - "all" - ] + "enum": ["initial", "async", "all"] }, { "instanceof": "Function" @@ -1555,10 +1495,7 @@ "type": "boolean" }, { - "enum": [ - "single", - "multiple" - ] + "enum": ["single", "multiple"] }, { "type": "object", @@ -1593,24 +1530,11 @@ }, "moduleIds": { "description": "Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: short hashes as ids for better long term caching, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin)", - "enum": [ - "natural", - "named", - "hashed", - "size", - "total-size", - false - ] + "enum": ["natural", "named", "hashed", "size", "total-size", false] }, "chunkIds": { "description": "Define the algorithm to choose chunk ids (named: readable ids for better debugging, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin)", - "enum": [ - "natural", - "named", - "size", - "total-size", - false - ] + "enum": ["natural", "named", "size", "total-size", false] }, "namedModules": { "description": "Use readable module identifiers for better debugging (deprecated, used moduleIds: named instead)", @@ -1651,9 +1575,7 @@ "description": "Set process.env.NODE_ENV to a specific value", "anyOf": [ { - "enum": [ - false - ] + "enum": [false] }, { "type": "string" @@ -1671,9 +1593,7 @@ "description": "Configuration for web performance recommendations.", "anyOf": [ { - "enum": [ - false - ] + "enum": [false] }, { "additionalProperties": false, @@ -1684,11 +1604,7 @@ }, "hints": { "description": "Sets the format of the hints: warnings, errors or nothing at all", - "enum": [ - false, - "warning", - "error" - ] + "enum": [false, "warning", "error"] }, "maxEntrypointSize": { "description": "Total size of an entry point (in bytes)", diff --git a/schemas/plugins/BannerPlugin.json b/schemas/plugins/BannerPlugin.json index 87e479036..6ebebcc5f 100644 --- a/schemas/plugins/BannerPlugin.json +++ b/schemas/plugins/BannerPlugin.json @@ -34,9 +34,7 @@ { "type": "object", "additionalProperties": false, - "required": [ - "banner" - ], + "required": ["banner"], "properties": { "banner": { "description": "Specifies the banner", diff --git a/schemas/plugins/DllPlugin.json b/schemas/plugins/DllPlugin.json index 940da62f1..c8ea5402f 100644 --- a/schemas/plugins/DllPlugin.json +++ b/schemas/plugins/DllPlugin.json @@ -1,8 +1,6 @@ { "additionalProperties": false, - "required": [ - "path" - ], + "required": ["path"], "properties": { "context": { "description": "Context of requests in the manifest file (defaults to the webpack context)", diff --git a/schemas/plugins/DllReferencePlugin.json b/schemas/plugins/DllReferencePlugin.json index 75fcff565..cd0c9ba86 100644 --- a/schemas/plugins/DllReferencePlugin.json +++ b/schemas/plugins/DllReferencePlugin.json @@ -2,14 +2,10 @@ "additionalProperties": false, "anyOf": [ { - "required": [ - "manifest" - ] + "required": ["manifest"] }, { - "required": [ - "content" - ] + "required": ["content"] } ], "properties": { @@ -60,10 +56,7 @@ }, "type": { "description": "The way how the export of the dll bundle is used", - "enum": [ - "require", - "object" - ] + "enum": ["require", "object"] }, "scope": { "description": "Prefix which is used for accessing the content of the dll", diff --git a/schemas/plugins/HashedModuleIdsPlugin.json b/schemas/plugins/HashedModuleIdsPlugin.json index 66ed722f6..30c6c71cc 100644 --- a/schemas/plugins/HashedModuleIdsPlugin.json +++ b/schemas/plugins/HashedModuleIdsPlugin.json @@ -9,11 +9,7 @@ }, "hashDigest": { "description": "The encoding to use when generating the hash, defaults to 'base64'. All encodings from Node.JS' hash.digest are supported.", - "enum": [ - "hex", - "latin1", - "base64" - ] + "enum": ["hex", "latin1", "base64"] }, "hashDigestLength": { "description": "The prefix length of the hash digest to use, defaults to 4.", diff --git a/schemas/plugins/SourceMapDevToolPlugin.json b/schemas/plugins/SourceMapDevToolPlugin.json index b0d11ae2a..e0f7d9b21 100644 --- a/schemas/plugins/SourceMapDevToolPlugin.json +++ b/schemas/plugins/SourceMapDevToolPlugin.json @@ -62,10 +62,7 @@ "oneOf": [ { "description": "Disable separate SourceMap file and inline SourceMap as DataUrl", - "enum": [ - false, - null - ] + "enum": [false, null] }, { "type": "string", @@ -79,10 +76,7 @@ "oneOf": [ { "description": "Append no SourceMap comment to the bundle, but still generate SourceMaps", - "enum": [ - false, - null - ] + "enum": [false, null] }, { "minLength": 1, diff --git a/schemas/plugins/optimize/MinChunkSizePlugin.json b/schemas/plugins/optimize/MinChunkSizePlugin.json index 2cb57a0b0..26b78da99 100644 --- a/schemas/plugins/optimize/MinChunkSizePlugin.json +++ b/schemas/plugins/optimize/MinChunkSizePlugin.json @@ -1,9 +1,7 @@ { "additionalProperties": false, "type": "object", - "required": [ - "minChunkSize" - ], + "required": ["minChunkSize"], "properties": { "minChunkSize": { "description": "Minimum number of characters", diff --git a/test/Schemas.lint.js b/test/Schemas.lint.js index 50fff3bad..075c39bfa 100644 --- a/test/Schemas.lint.js +++ b/test/Schemas.lint.js @@ -28,12 +28,6 @@ describe("Schemas", () => { }); if (content) { - it("should be formated correctly", () => { - expect(fileContent.replace(/\r\n?/g, "\n")).toBe( - JSON.stringify(content, 0, 2) + "\n" - ); - }); - const arrayProperties = ["oneOf", "anyOf", "allOf"]; const allowedProperties = [ "definitions", diff --git a/tsconfig.json b/tsconfig.json index d265178d6..e94475dc7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,16 @@ { - "compilerOptions": { - "target": "ES2017", - "module": "commonjs", - "lib": ["es2017", "dom"], - "allowJs": true, - "checkJs": true, - "noEmit": true, - "strict": false, - "noImplicitThis": true, - "alwaysStrict": true, - "types": ["node"], - "esModuleInterop": true - }, - "include": ["declarations.d.ts", "bin/*.js", "lib/**/*.js", "tooling/**/*.js"] + "compilerOptions": { + "target": "ES2017", + "module": "commonjs", + "lib": ["es2017", "dom"], + "allowJs": true, + "checkJs": true, + "noEmit": true, + "strict": false, + "noImplicitThis": true, + "alwaysStrict": true, + "types": ["node"], + "esModuleInterop": true + }, + "include": ["declarations.d.ts", "bin/*.js", "lib/**/*.js", "tooling/**/*.js"] }