improve prettier and lint config and performance

This commit is contained in:
Tobias Koppers 2018-08-24 16:57:16 +02:00
parent 6e01fd5099
commit 1b886ee342
14 changed files with 89 additions and 199 deletions

View File

@ -8,10 +8,6 @@ trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
max_line_length = 80 max_line_length = 80
[.prettierrc]
indent_style = space
indent_size = 2
[*.{yml,yaml,json}] [*.{yml,yaml,json}]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

View File

@ -1,7 +1,11 @@
module.exports = { module.exports = {
root: true, root: true,
plugins: ["prettier", "node", "jest"], plugins: ["prettier", "node", "jest"],
extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"], extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:prettier/recommended"
],
env: { env: {
node: true, node: true,
es6: true es6: true
@ -16,8 +20,8 @@ module.exports = {
"no-template-curly-in-string": "error", "no-template-curly-in-string": "error",
"no-caller": "error", "no-caller": "error",
"no-control-regex": "off", "no-control-regex": "off",
"yoda": "error", yoda: "error",
"eqeqeq": "error", eqeqeq: "error",
"global-require": "off", "global-require": "off",
"brace-style": "error", "brace-style": "error",
"eol-last": "error", "eol-last": "error",
@ -27,23 +31,26 @@ module.exports = {
"no-unused-vars": ["error", { args: "none" }], "no-unused-vars": ["error", { args: "none" }],
"no-unsafe-negation": "error", "no-unsafe-negation": "error",
"no-loop-func": "warn", "no-loop-func": "warn",
"indent": "off", indent: "off",
"no-console": "off", "no-console": "off",
"valid-jsdoc": ["error", { "valid-jsdoc": [
"prefer": { "error",
"return": "returns", {
"prop": "property", prefer: {
"memberof": "DONTUSE", return: "returns",
"class": "DONTUSE", prop: "property",
"inheritdoc": "DONTUSE", memberof: "DONTUSE",
"description": "DONTUSE", class: "DONTUSE",
"readonly": "DONTUSE" inheritdoc: "DONTUSE",
}, description: "DONTUSE",
"preferType": { readonly: "DONTUSE"
"*": "any" },
}, preferType: {
"requireReturnType": true "*": "any"
}], },
requireReturnType: true
}
],
"node/no-unsupported-features": "error", "node/no-unsupported-features": "error",
"node/no-deprecated-api": "error", "node/no-deprecated-api": "error",
"node/no-missing-import": "error", "node/no-missing-import": "error",

View File

@ -1,16 +1,8 @@
# Ignore all paths. # Ignore test fixtures
**/*.* test
# Enable prettier for the following paths.
!*.{ts,js,json}
!setup/**/*.js
!lib/**/*.js
!bin/*.js
!hot/*.js
!buildin/*.js
!benchmark/**/*.js
!test/*.js !test/*.js
!tooling/*.js
!test/**/webpack.config.js !test/**/webpack.config.js
# Ignore example fixtures
examples
!examples/**/webpack.config.js !examples/**/webpack.config.js
!schemas/**/*.js

View File

@ -1,5 +1,13 @@
module.exports = { module.exports = {
printWidth: 80, printWidth: 80,
useTabs: true, useTabs: true,
tabWidth: 2 tabWidth: 2,
overrides: [
{
files: "*.json",
options: {
useTabs: false
}
}
]
}; };

View File

@ -120,10 +120,10 @@
"pretest": "yarn lint", "pretest": "yarn lint",
"prelint": "yarn setup", "prelint": "yarn setup",
"lint": "yarn code-lint && yarn schema-lint && yarn type-lint", "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", "type-lint": "tsc --pretty",
"fix": "yarn code-lint --fix", "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 \"<rootDir>/test/*.lint.js\" --no-verbose", "schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.lint.js\" --no-verbose",
"benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand",
"cover": "yarn cover:init && yarn cover:all && yarn cover:report", "cover": "yarn cover:init && yarn cover:all && yarn cover:report",

View File

@ -11,9 +11,7 @@
} }
}, },
"additionalProperties": true, "additionalProperties": true,
"required": [ "required": ["apply"]
"apply"
]
}, },
"common.pluginObject": { "common.pluginObject": {
"description": "Plugin instance", "description": "Plugin instance",
@ -25,9 +23,7 @@
} }
}, },
"additionalProperties": true, "additionalProperties": true,
"required": [ "required": ["apply"]
"apply"
]
}, },
"common.arrayOfStringOrStringArrayValues": { "common.arrayOfStringOrStringArrayValues": {
"items": { "items": {
@ -339,19 +335,11 @@
}, },
"crossOriginLoading": { "crossOriginLoading": {
"description": "This option enables cross-origin loading of chunks.", "description": "This option enables cross-origin loading of chunks.",
"enum": [ "enum": [false, "anonymous", "use-credentials"]
false,
"anonymous",
"use-credentials"
]
}, },
"jsonpScriptType": { "jsonpScriptType": {
"description": "This option enables loading async chunks via a custom script type, such as script type=\"module\"", "description": "This option enables loading async chunks via a custom script type, such as script type=\"module\"",
"enum": [ "enum": [false, "text/javascript", "module"]
false,
"text/javascript",
"module"
]
}, },
"chunkLoadTimeout": { "chunkLoadTimeout": {
"description": "Number of milliseconds before chunk request expires", "description": "Number of milliseconds before chunk request expires",
@ -837,10 +825,7 @@
"properties": { "properties": {
"enforce": { "enforce": {
"description": "Enforce this rule as pre or post step", "description": "Enforce this rule as pre or post step",
"enum": [ "enum": ["pre", "post"]
"pre",
"post"
]
}, },
"exclude": { "exclude": {
"description": "Shortcut for resource.exclude", "description": "Shortcut for resource.exclude",
@ -1114,11 +1099,7 @@
"properties": { "properties": {
"mode": { "mode": {
"description": "Enable production optimizations or development hints.", "description": "Enable production optimizations or development hints.",
"enum": [ "enum": ["development", "production", "none"]
"development",
"production",
"none"
]
}, },
"amd": { "amd": {
"description": "Set the value of `require.amd` and `define.amd`." "description": "Set the value of `require.amd` and `define.amd`."
@ -1164,9 +1145,7 @@
"type": "string" "type": "string"
}, },
{ {
"enum": [ "enum": [false]
false
]
} }
] ]
}, },
@ -1206,52 +1185,29 @@
"description": "Include polyfills or mocks for various node stuff.", "description": "Include polyfills or mocks for various node stuff.",
"anyOf": [ "anyOf": [
{ {
"enum": [ "enum": [false]
false
]
}, },
{ {
"additionalProperties": { "additionalProperties": {
"description": "Include a polyfill for the node.js module", "description": "Include a polyfill for the node.js module",
"enum": [ "enum": [false, true, "mock", "empty"]
false,
true,
"mock",
"empty"
]
}, },
"properties": { "properties": {
"Buffer": { "Buffer": {
"description": "Include a polyfill for the 'Buffer' variable", "description": "Include a polyfill for the 'Buffer' variable",
"enum": [ "enum": [false, true, "mock"]
false,
true,
"mock"
]
}, },
"__dirname": { "__dirname": {
"description": "Include a polyfill for the '__dirname' variable", "description": "Include a polyfill for the '__dirname' variable",
"enum": [ "enum": [false, true, "mock"]
false,
true,
"mock"
]
}, },
"__filename": { "__filename": {
"description": "Include a polyfill for the '__filename' variable", "description": "Include a polyfill for the '__filename' variable",
"enum": [ "enum": [false, true, "mock"]
false,
true,
"mock"
]
}, },
"console": { "console": {
"description": "Include a polyfill for the 'console' variable", "description": "Include a polyfill for the 'console' variable",
"enum": [ "enum": [false, true, "mock"]
false,
true,
"mock"
]
}, },
"global": { "global": {
"description": "Include a polyfill for the 'global' variable", "description": "Include a polyfill for the 'global' variable",
@ -1259,11 +1215,7 @@
}, },
"process": { "process": {
"description": "Include a polyfill for the 'process' variable", "description": "Include a polyfill for the 'process' variable",
"enum": [ "enum": [false, true, "mock"]
false,
true,
"mock"
]
} }
}, },
"type": "object" "type": "object"
@ -1323,9 +1275,7 @@
"description": "Optimize duplication and caching by splitting chunks by shared modules and cache group", "description": "Optimize duplication and caching by splitting chunks by shared modules and cache group",
"oneOf": [ "oneOf": [
{ {
"enum": [ "enum": [false]
false
]
}, },
{ {
"type": "object", "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)", "description": "Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML)",
"oneOf": [ "oneOf": [
{ {
"enum": [ "enum": ["initial", "async", "all"]
"initial",
"async",
"all"
]
}, },
{ {
"instanceof": "Function" "instanceof": "Function"
@ -1428,9 +1374,7 @@
"description": "Configuration for a cache group", "description": "Configuration for a cache group",
"anyOf": [ "anyOf": [
{ {
"enum": [ "enum": [false]
false
]
}, },
{ {
"instanceof": "Function" "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)", "description": "Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML)",
"oneOf": [ "oneOf": [
{ {
"enum": [ "enum": ["initial", "async", "all"]
"initial",
"async",
"all"
]
}, },
{ {
"instanceof": "Function" "instanceof": "Function"
@ -1555,10 +1495,7 @@
"type": "boolean" "type": "boolean"
}, },
{ {
"enum": [ "enum": ["single", "multiple"]
"single",
"multiple"
]
}, },
{ {
"type": "object", "type": "object",
@ -1593,24 +1530,11 @@
}, },
"moduleIds": { "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)", "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": [ "enum": ["natural", "named", "hashed", "size", "total-size", false]
"natural",
"named",
"hashed",
"size",
"total-size",
false
]
}, },
"chunkIds": { "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)", "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": [ "enum": ["natural", "named", "size", "total-size", false]
"natural",
"named",
"size",
"total-size",
false
]
}, },
"namedModules": { "namedModules": {
"description": "Use readable module identifiers for better debugging (deprecated, used moduleIds: named instead)", "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", "description": "Set process.env.NODE_ENV to a specific value",
"anyOf": [ "anyOf": [
{ {
"enum": [ "enum": [false]
false
]
}, },
{ {
"type": "string" "type": "string"
@ -1671,9 +1593,7 @@
"description": "Configuration for web performance recommendations.", "description": "Configuration for web performance recommendations.",
"anyOf": [ "anyOf": [
{ {
"enum": [ "enum": [false]
false
]
}, },
{ {
"additionalProperties": false, "additionalProperties": false,
@ -1684,11 +1604,7 @@
}, },
"hints": { "hints": {
"description": "Sets the format of the hints: warnings, errors or nothing at all", "description": "Sets the format of the hints: warnings, errors or nothing at all",
"enum": [ "enum": [false, "warning", "error"]
false,
"warning",
"error"
]
}, },
"maxEntrypointSize": { "maxEntrypointSize": {
"description": "Total size of an entry point (in bytes)", "description": "Total size of an entry point (in bytes)",

View File

@ -34,9 +34,7 @@
{ {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": ["banner"],
"banner"
],
"properties": { "properties": {
"banner": { "banner": {
"description": "Specifies the banner", "description": "Specifies the banner",

View File

@ -1,8 +1,6 @@
{ {
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": ["path"],
"path"
],
"properties": { "properties": {
"context": { "context": {
"description": "Context of requests in the manifest file (defaults to the webpack context)", "description": "Context of requests in the manifest file (defaults to the webpack context)",

View File

@ -2,14 +2,10 @@
"additionalProperties": false, "additionalProperties": false,
"anyOf": [ "anyOf": [
{ {
"required": [ "required": ["manifest"]
"manifest"
]
}, },
{ {
"required": [ "required": ["content"]
"content"
]
} }
], ],
"properties": { "properties": {
@ -60,10 +56,7 @@
}, },
"type": { "type": {
"description": "The way how the export of the dll bundle is used", "description": "The way how the export of the dll bundle is used",
"enum": [ "enum": ["require", "object"]
"require",
"object"
]
}, },
"scope": { "scope": {
"description": "Prefix which is used for accessing the content of the dll", "description": "Prefix which is used for accessing the content of the dll",

View File

@ -9,11 +9,7 @@
}, },
"hashDigest": { "hashDigest": {
"description": "The encoding to use when generating the hash, defaults to 'base64'. All encodings from Node.JS' hash.digest are supported.", "description": "The encoding to use when generating the hash, defaults to 'base64'. All encodings from Node.JS' hash.digest are supported.",
"enum": [ "enum": ["hex", "latin1", "base64"]
"hex",
"latin1",
"base64"
]
}, },
"hashDigestLength": { "hashDigestLength": {
"description": "The prefix length of the hash digest to use, defaults to 4.", "description": "The prefix length of the hash digest to use, defaults to 4.",

View File

@ -62,10 +62,7 @@
"oneOf": [ "oneOf": [
{ {
"description": "Disable separate SourceMap file and inline SourceMap as DataUrl", "description": "Disable separate SourceMap file and inline SourceMap as DataUrl",
"enum": [ "enum": [false, null]
false,
null
]
}, },
{ {
"type": "string", "type": "string",
@ -79,10 +76,7 @@
"oneOf": [ "oneOf": [
{ {
"description": "Append no SourceMap comment to the bundle, but still generate SourceMaps", "description": "Append no SourceMap comment to the bundle, but still generate SourceMaps",
"enum": [ "enum": [false, null]
false,
null
]
}, },
{ {
"minLength": 1, "minLength": 1,

View File

@ -1,9 +1,7 @@
{ {
"additionalProperties": false, "additionalProperties": false,
"type": "object", "type": "object",
"required": [ "required": ["minChunkSize"],
"minChunkSize"
],
"properties": { "properties": {
"minChunkSize": { "minChunkSize": {
"description": "Minimum number of characters", "description": "Minimum number of characters",

View File

@ -28,12 +28,6 @@ describe("Schemas", () => {
}); });
if (content) { 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 arrayProperties = ["oneOf", "anyOf", "allOf"];
const allowedProperties = [ const allowedProperties = [
"definitions", "definitions",

View File

@ -1,16 +1,16 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2017", "target": "ES2017",
"module": "commonjs", "module": "commonjs",
"lib": ["es2017", "dom"], "lib": ["es2017", "dom"],
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"noEmit": true, "noEmit": true,
"strict": false, "strict": false,
"noImplicitThis": true, "noImplicitThis": true,
"alwaysStrict": true, "alwaysStrict": true,
"types": ["node"], "types": ["node"],
"esModuleInterop": true "esModuleInterop": true
}, },
"include": ["declarations.d.ts", "bin/*.js", "lib/**/*.js", "tooling/**/*.js"] "include": ["declarations.d.ts", "bin/*.js", "lib/**/*.js", "tooling/**/*.js"]
} }