eslint-config-prettier 6.13.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js CHANGED
@@ -4,38 +4,35 @@
4
4
 
5
5
  const fs = require("fs");
6
6
  const path = require("path");
7
- const getStdin = require("get-stdin");
8
7
  const validators = require("./validators");
9
8
 
9
+ // Require locally installed eslint, for `npx eslint-config-prettier` support
10
+ // with no local eslint-config-prettier installation.
11
+ const { ESLint } = require(require.resolve("eslint", {
12
+ paths: [process.cwd(), ...require.resolve.paths("eslint")],
13
+ }));
14
+
10
15
  const SPECIAL_RULES_URL =
11
16
  "https://github.com/prettier/eslint-config-prettier#special-rules";
12
17
 
13
18
  if (module === require.main) {
14
- if (process.argv.length > 2 || process.stdin.isTTY) {
15
- console.error(
16
- [
17
- "This tool checks whether an ESLint configuration contains rules that are",
18
- "unnecessary or conflict with Prettier. It’s supposed to be run like this:",
19
- "",
20
- " npx eslint --print-config path/to/main.js | npx eslint-config-prettier-check",
21
- " npx eslint --print-config test/index.js | npx eslint-config-prettier-check",
22
- "",
23
- "Exit codes:",
24
- "",
25
- "0: No automatically detectable problems found.",
26
- "1: Unexpected error.",
27
- "2: Conflicting rules found.",
28
- "",
29
- "For more information, see:",
30
- "https://github.com/prettier/eslint-config-prettier#cli-helper-tool",
31
- ].join("\n")
32
- );
19
+ const args = process.argv.slice(2);
20
+
21
+ if (args.length === 0) {
22
+ console.error(help());
33
23
  process.exit(1);
34
24
  }
35
25
 
36
- getStdin()
37
- .then((string) => {
38
- const result = processString(string);
26
+ const eslint = new ESLint();
27
+
28
+ Promise.all(args.map((file) => eslint.calculateConfigForFile(file)))
29
+ .then((configs) => {
30
+ const rules = [].concat(
31
+ ...configs.map((config, index) =>
32
+ Object.entries(config.rules).map((entry) => [...entry, args[index]])
33
+ )
34
+ );
35
+ const result = processRules(rules);
39
36
  if (result.stderr) {
40
37
  console.error(result.stderr);
41
38
  }
@@ -45,34 +42,32 @@ if (module === require.main) {
45
42
  process.exit(result.code);
46
43
  })
47
44
  .catch((error) => {
48
- console.error("Unexpected error", error);
45
+ console.error(error.message);
49
46
  process.exit(1);
50
47
  });
51
48
  }
52
49
 
53
- function processString(string) {
54
- let config;
55
- try {
56
- config = JSON.parse(string);
57
- } catch (error) {
58
- return {
59
- stderr: `Failed to parse JSON:\n${error.message}`,
60
- code: 1,
61
- };
62
- }
50
+ function help() {
51
+ return `
52
+ Usage: npx eslint-config-prettier FILE...
63
53
 
64
- if (
65
- !(
66
- Object.prototype.toString.call(config) === "[object Object]" &&
67
- Object.prototype.toString.call(config.rules) === "[object Object]"
68
- )
69
- ) {
70
- return {
71
- stderr: `Expected a \`{"rules: {...}"}\` JSON object, but got:\n${string}`,
72
- code: 1,
73
- };
74
- }
54
+ Resolves an ESLint configuration for every given FILE and checks if they
55
+ contain rules that are unnecessary or conflict with Prettier. Example:
56
+
57
+ npx eslint-config-prettier index.js test/index.js other/file/to/check.js
58
+
59
+ Exit codes:
60
+
61
+ 0: No automatically detectable problems found.
62
+ 1: General error.
63
+ 2: Conflicting rules found.
64
+
65
+ For more information, see:
66
+ https://github.com/prettier/eslint-config-prettier#cli-helper-tool
67
+ `.trim();
68
+ }
75
69
 
70
+ function processRules(configRules) {
76
71
  // This used to look at "files" in package.json, but that is not reliable due
77
72
  // to an npm bug. See:
78
73
  // https://github.com/prettier/eslint-config-prettier/issues/57
@@ -84,10 +79,7 @@ function processString(string) {
84
79
  .map((ruleFileName) => require(`../${ruleFileName}`).rules)
85
80
  );
86
81
 
87
- const regularRules = filterRules(
88
- allRules,
89
- (ruleName, value) => value === "off"
90
- );
82
+ const regularRules = filterRules(allRules, (_, value) => value === "off");
91
83
  const optionsRules = filterRules(
92
84
  allRules,
93
85
  (ruleName, value) => value === 0 && ruleName in validators
@@ -97,29 +89,31 @@ function processString(string) {
97
89
  (ruleName, value) => value === 0 && !(ruleName in validators)
98
90
  );
99
91
 
100
- const flaggedRules = Object.keys(config.rules)
101
- .map((ruleName) => {
102
- const value = config.rules[ruleName];
92
+ const enabledRules = configRules
93
+ .map(([ruleName, value, source]) => {
103
94
  const arrayValue = Array.isArray(value) ? value : [value];
104
- const level = arrayValue[0];
105
- const options = arrayValue.slice(1);
95
+ const [level, ...options] = arrayValue;
106
96
  const isOff = level === "off" || level === 0;
107
- return !isOff && ruleName in allRules ? { ruleName, options } : null;
97
+ return isOff ? null : { ruleName, options, source };
108
98
  })
109
99
  .filter(Boolean);
110
100
 
101
+ const flaggedRules = enabledRules.filter(
102
+ ({ ruleName }) => ruleName in allRules
103
+ );
104
+
111
105
  const regularFlaggedRuleNames = filterRuleNames(
112
106
  flaggedRules,
113
- (ruleName) => ruleName in regularRules
107
+ ({ ruleName }) => ruleName in regularRules
114
108
  );
115
109
  const optionsFlaggedRuleNames = filterRuleNames(
116
110
  flaggedRules,
117
- (ruleName, options) =>
118
- ruleName in optionsRules && !validators[ruleName](options)
111
+ ({ ruleName, ...rule }) =>
112
+ ruleName in optionsRules && !validators[ruleName](rule, enabledRules)
119
113
  );
120
114
  const specialFlaggedRuleNames = filterRuleNames(
121
115
  flaggedRules,
122
- (ruleName) => ruleName in specialRules
116
+ ({ ruleName }) => ruleName in specialRules
123
117
  );
124
118
 
125
119
  if (
@@ -154,7 +148,7 @@ function processString(string) {
154
148
  ].join("\n");
155
149
 
156
150
  const optionsMessage = [
157
- "The following rules are enabled with options that might conflict with Prettier. See:",
151
+ "The following rules are enabled with config that might conflict with Prettier. See:",
158
152
  SPECIAL_RULES_URL,
159
153
  "",
160
154
  printRuleNames(optionsFlaggedRuleNames),
@@ -182,18 +176,18 @@ function processString(string) {
182
176
  }
183
177
 
184
178
  function filterRules(rules, fn) {
185
- return Object.keys(rules)
186
- .filter((ruleName) => fn(ruleName, rules[ruleName]))
187
- .reduce((obj, ruleName) => {
179
+ return Object.entries(rules)
180
+ .filter(([ruleName, value]) => fn(ruleName, value))
181
+ .reduce((obj, [ruleName]) => {
188
182
  obj[ruleName] = true;
189
183
  return obj;
190
184
  }, Object.create(null));
191
185
  }
192
186
 
193
187
  function filterRuleNames(rules, fn) {
194
- return rules
195
- .filter((rule) => fn(rule.ruleName, rule.options))
196
- .map((rule) => rule.ruleName);
188
+ return [
189
+ ...new Set(rules.filter((rule) => fn(rule)).map((rule) => rule.ruleName)),
190
+ ];
197
191
  }
198
192
 
199
193
  function printRuleNames(ruleNames) {
@@ -204,4 +198,4 @@ function printRuleNames(ruleNames) {
204
198
  .join("\n");
205
199
  }
206
200
 
207
- exports.processString = processString;
201
+ exports.processRules = processRules;
package/bin/validators.js CHANGED
@@ -4,7 +4,9 @@
4
4
  // `false` if the options DO conflict with Prettier, and `true` if they don’t.
5
5
 
6
6
  module.exports = {
7
- curly(options) {
7
+ "arrow-body-style": checkEslintPluginPrettier,
8
+
9
+ curly({ options }) {
8
10
  if (options.length === 0) {
9
11
  return true;
10
12
  }
@@ -13,7 +15,7 @@ module.exports = {
13
15
  return firstOption !== "multi-line" && firstOption !== "multi-or-nest";
14
16
  },
15
17
 
16
- "lines-around-comment"(options) {
18
+ "lines-around-comment"({ options }) {
17
19
  if (options.length === 0) {
18
20
  return false;
19
21
  }
@@ -30,7 +32,7 @@ module.exports = {
30
32
  );
31
33
  },
32
34
 
33
- "no-confusing-arrow"(options) {
35
+ "no-confusing-arrow"({ options }) {
34
36
  if (options.length === 0) {
35
37
  return false;
36
38
  }
@@ -39,7 +41,18 @@ module.exports = {
39
41
  return firstOption ? firstOption.allowParens === false : false;
40
42
  },
41
43
 
42
- "vue/html-self-closing"(options) {
44
+ "no-tabs"({ options }) {
45
+ if (options.length === 0) {
46
+ return false;
47
+ }
48
+
49
+ const firstOption = options[0];
50
+ return Boolean(firstOption && firstOption.allowIndentationTabs);
51
+ },
52
+
53
+ "prefer-arrow-callback": checkEslintPluginPrettier,
54
+
55
+ "vue/html-self-closing"({ options }) {
43
56
  if (options.length === 0) {
44
57
  return false;
45
58
  }
@@ -52,3 +65,10 @@ module.exports = {
52
65
  );
53
66
  },
54
67
  };
68
+
69
+ function checkEslintPluginPrettier({ source: currentSource }, enabledRules) {
70
+ return !enabledRules.some(
71
+ ({ ruleName, source }) =>
72
+ ruleName === "prettier/prettier" && currentSource === source
73
+ );
74
+ }
package/index.js CHANGED
@@ -3,101 +3,97 @@
3
3
  const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED;
4
4
 
5
5
  module.exports = {
6
- rules: Object.assign(
7
- {
8
- // The following rules can be used in some cases. See the README for more
9
- // information. (These are marked with `0` instead of `"off"` so that a
10
- // script can distinguish them.)
11
- "arrow-body-style": 0,
12
- curly: 0,
13
- "lines-around-comment": 0,
14
- "max-len": 0,
15
- "no-confusing-arrow": 0,
16
- "no-mixed-operators": 0,
17
- "no-tabs": 0,
18
- "no-unexpected-multiline": 0,
19
- "prefer-arrow-callback": 0,
20
- quotes: 0,
21
- // The rest are rules that you never need to enable when using Prettier.
22
- "array-bracket-newline": "off",
23
- "array-bracket-spacing": "off",
24
- "array-element-newline": "off",
25
- "arrow-parens": "off",
26
- "arrow-spacing": "off",
27
- "block-spacing": "off",
28
- "brace-style": "off",
29
- "comma-dangle": "off",
30
- "comma-spacing": "off",
31
- "comma-style": "off",
32
- "computed-property-spacing": "off",
33
- "dot-location": "off",
34
- "eol-last": "off",
35
- "func-call-spacing": "off",
36
- "function-call-argument-newline": "off",
37
- "function-paren-newline": "off",
38
- "generator-star": "off",
39
- "generator-star-spacing": "off",
40
- "implicit-arrow-linebreak": "off",
41
- indent: "off",
42
- "jsx-quotes": "off",
43
- "key-spacing": "off",
44
- "keyword-spacing": "off",
45
- "linebreak-style": "off",
46
- "multiline-ternary": "off",
47
- "newline-per-chained-call": "off",
48
- "new-parens": "off",
49
- "no-arrow-condition": "off",
50
- "no-comma-dangle": "off",
51
- "no-extra-parens": "off",
52
- "no-extra-semi": "off",
53
- "no-floating-decimal": "off",
54
- "no-mixed-spaces-and-tabs": "off",
55
- "no-multi-spaces": "off",
56
- "no-multiple-empty-lines": "off",
57
- "no-reserved-keys": "off",
58
- "no-space-before-semi": "off",
59
- "no-trailing-spaces": "off",
60
- "no-whitespace-before-property": "off",
61
- "no-wrap-func": "off",
62
- "nonblock-statement-body-position": "off",
63
- "object-curly-newline": "off",
64
- "object-curly-spacing": "off",
65
- "object-property-newline": "off",
66
- "one-var-declaration-per-line": "off",
67
- "operator-linebreak": "off",
68
- "padded-blocks": "off",
69
- "quote-props": "off",
70
- "rest-spread-spacing": "off",
71
- semi: "off",
72
- "semi-spacing": "off",
73
- "semi-style": "off",
74
- "space-after-function-name": "off",
75
- "space-after-keywords": "off",
76
- "space-before-blocks": "off",
77
- "space-before-function-paren": "off",
78
- "space-before-function-parentheses": "off",
79
- "space-before-keywords": "off",
80
- "space-in-brackets": "off",
81
- "space-in-parens": "off",
82
- "space-infix-ops": "off",
83
- "space-return-throw-case": "off",
84
- "space-unary-ops": "off",
85
- "space-unary-word-ops": "off",
86
- "switch-colon-spacing": "off",
87
- "template-curly-spacing": "off",
88
- "template-tag-spacing": "off",
89
- "unicode-bom": "off",
90
- "wrap-iife": "off",
91
- "wrap-regex": "off",
92
- "yield-star-spacing": "off",
93
- },
94
- includeDeprecated && {
6
+ rules: {
7
+ // The following rules can be used in some cases. See the README for more
8
+ // information. (These are marked with `0` instead of `"off"` so that a
9
+ // script can distinguish them.)
10
+ curly: 0,
11
+ "lines-around-comment": 0,
12
+ "max-len": 0,
13
+ "no-confusing-arrow": 0,
14
+ "no-mixed-operators": 0,
15
+ "no-tabs": 0,
16
+ "no-unexpected-multiline": 0,
17
+ quotes: 0,
18
+ // The rest are rules that you never need to enable when using Prettier.
19
+ "array-bracket-newline": "off",
20
+ "array-bracket-spacing": "off",
21
+ "array-element-newline": "off",
22
+ "arrow-parens": "off",
23
+ "arrow-spacing": "off",
24
+ "block-spacing": "off",
25
+ "brace-style": "off",
26
+ "comma-dangle": "off",
27
+ "comma-spacing": "off",
28
+ "comma-style": "off",
29
+ "computed-property-spacing": "off",
30
+ "dot-location": "off",
31
+ "eol-last": "off",
32
+ "func-call-spacing": "off",
33
+ "function-call-argument-newline": "off",
34
+ "function-paren-newline": "off",
35
+ "generator-star": "off",
36
+ "generator-star-spacing": "off",
37
+ "implicit-arrow-linebreak": "off",
38
+ indent: "off",
39
+ "jsx-quotes": "off",
40
+ "key-spacing": "off",
41
+ "keyword-spacing": "off",
42
+ "linebreak-style": "off",
43
+ "multiline-ternary": "off",
44
+ "newline-per-chained-call": "off",
45
+ "new-parens": "off",
46
+ "no-arrow-condition": "off",
47
+ "no-comma-dangle": "off",
48
+ "no-extra-parens": "off",
49
+ "no-extra-semi": "off",
50
+ "no-floating-decimal": "off",
51
+ "no-mixed-spaces-and-tabs": "off",
52
+ "no-multi-spaces": "off",
53
+ "no-multiple-empty-lines": "off",
54
+ "no-reserved-keys": "off",
55
+ "no-space-before-semi": "off",
56
+ "no-trailing-spaces": "off",
57
+ "no-whitespace-before-property": "off",
58
+ "no-wrap-func": "off",
59
+ "nonblock-statement-body-position": "off",
60
+ "object-curly-newline": "off",
61
+ "object-curly-spacing": "off",
62
+ "object-property-newline": "off",
63
+ "one-var-declaration-per-line": "off",
64
+ "operator-linebreak": "off",
65
+ "padded-blocks": "off",
66
+ "quote-props": "off",
67
+ "rest-spread-spacing": "off",
68
+ semi: "off",
69
+ "semi-spacing": "off",
70
+ "semi-style": "off",
71
+ "space-after-function-name": "off",
72
+ "space-after-keywords": "off",
73
+ "space-before-blocks": "off",
74
+ "space-before-function-paren": "off",
75
+ "space-before-function-parentheses": "off",
76
+ "space-before-keywords": "off",
77
+ "space-in-brackets": "off",
78
+ "space-in-parens": "off",
79
+ "space-infix-ops": "off",
80
+ "space-return-throw-case": "off",
81
+ "space-unary-ops": "off",
82
+ "space-unary-word-ops": "off",
83
+ "switch-colon-spacing": "off",
84
+ "template-curly-spacing": "off",
85
+ "template-tag-spacing": "off",
86
+ "unicode-bom": "off",
87
+ "wrap-iife": "off",
88
+ "wrap-regex": "off",
89
+ "yield-star-spacing": "off",
90
+ ...(includeDeprecated && {
95
91
  // Deprecated since version 4.0.0.
96
92
  // https://github.com/eslint/eslint/pull/8286
97
93
  "indent-legacy": "off",
98
94
  // Deprecated since version 3.3.0.
99
95
  // https://eslint.org/docs/rules/no-spaced-func
100
96
  "no-spaced-func": "off",
101
- }
102
- ),
97
+ }),
98
+ },
103
99
  };
package/package.json CHANGED
@@ -1,67 +1,13 @@
1
1
  {
2
2
  "name": "eslint-config-prettier",
3
- "version": "6.13.0",
3
+ "version": "7.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Simon Lydell",
6
6
  "description": "Turns off all rules that are unnecessary or might conflict with Prettier.",
7
7
  "repository": "prettier/eslint-config-prettier",
8
- "files": [
9
- "bin/",
10
- "@typescript-eslint.js",
11
- "babel.js",
12
- "flowtype.js",
13
- "index.js",
14
- "react.js",
15
- "standard.js",
16
- "unicorn.js",
17
- "vue.js"
18
- ],
19
- "bin": {
20
- "eslint-config-prettier-check": "bin/cli.js"
21
- },
22
- "keywords": [
23
- "eslint",
24
- "eslintconfig",
25
- "prettier"
26
- ],
27
- "scripts": {
28
- "doctoc": "doctoc README.md && replace \"\\[\\[([\\w/-]+)\\](?:([^\\[\\]]+)\\[([\\w/-]+)\\])?\\]\" \"[\\$1\\$2\\$3]\" README.md",
29
- "prettier": "prettier --write .",
30
- "test:lint": "eslint . && prettier --check .",
31
- "test:lint-verify-fail": "eslint \"test-lint/*.{js,ts,vue}\" --config .eslintrc.base.js --format json",
32
- "test:lint-rules": "eslint index.js --config test-config/.eslintrc.js --format json",
33
- "test:deprecated": "eslint-find-rules --deprecated index.js",
34
- "test:jest": "jest",
35
- "test:cli-sanity": "eslint --print-config index.js | node ./bin/cli.js",
36
- "test:cli-sanity-warning": "eslint --print-config ./bin/cli.js | node ./bin/cli.js",
37
- "test": "npm run test:lint && npm run test:jest && npm run test:cli-sanity && npm run test:cli-sanity-warning"
38
- },
39
- "dependencies": {
40
- "get-stdin": "^6.0.0"
41
- },
42
- "devDependencies": {
43
- "@typescript-eslint/eslint-plugin": "4.4.1",
44
- "@typescript-eslint/parser": "4.4.1",
45
- "babel-eslint": "10.1.0",
46
- "cross-spawn": "7.0.3",
47
- "doctoc": "1.4.0",
48
- "eslint": "7.11.0",
49
- "eslint-config-google": "0.14.0",
50
- "eslint-find-rules": "3.6.1",
51
- "eslint-plugin-babel": "5.3.1",
52
- "eslint-plugin-flowtype": "5.2.0",
53
- "eslint-plugin-prettier": "3.1.4",
54
- "eslint-plugin-react": "7.21.4",
55
- "eslint-plugin-standard": "4.0.1",
56
- "eslint-plugin-unicorn": "22.0.0",
57
- "eslint-plugin-vue": "7.0.1",
58
- "jest": "26.5.3",
59
- "prettier": "2.1.2",
60
- "replace": "1.2.0",
61
- "rimraf": "3.0.2",
62
- "typescript": "4.0.3"
63
- },
8
+ "bin": "bin/cli.js",
9
+ "keywords": ["eslint", "eslintconfig", "prettier"],
64
10
  "peerDependencies": {
65
- "eslint": ">=3.14.1"
11
+ "eslint": ">=7.0.0"
66
12
  }
67
13
  }
package/prettier.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ rules: {
5
+ // These are safe to use as long as the `"prettier/prettier"` rule from
6
+ // eslint-plugin-prettier isn’t enabled.
7
+ // These are also included in `"plugin:prettier/recommended"`:
8
+ // https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
9
+ "arrow-body-style": 0,
10
+ "prefer-arrow-callback": 0,
11
+ },
12
+ };
package/react.js CHANGED
@@ -3,27 +3,25 @@
3
3
  const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED;
4
4
 
5
5
  module.exports = {
6
- rules: Object.assign(
7
- {
8
- "react/jsx-child-element-spacing": "off",
9
- "react/jsx-closing-bracket-location": "off",
10
- "react/jsx-closing-tag-location": "off",
11
- "react/jsx-curly-newline": "off",
12
- "react/jsx-curly-spacing": "off",
13
- "react/jsx-equals-spacing": "off",
14
- "react/jsx-first-prop-new-line": "off",
15
- "react/jsx-indent": "off",
16
- "react/jsx-indent-props": "off",
17
- "react/jsx-max-props-per-line": "off",
18
- "react/jsx-one-expression-per-line": "off",
19
- "react/jsx-props-no-multi-spaces": "off",
20
- "react/jsx-tag-spacing": "off",
21
- "react/jsx-wrap-multilines": "off",
22
- },
23
- includeDeprecated && {
6
+ rules: {
7
+ "react/jsx-child-element-spacing": "off",
8
+ "react/jsx-closing-bracket-location": "off",
9
+ "react/jsx-closing-tag-location": "off",
10
+ "react/jsx-curly-newline": "off",
11
+ "react/jsx-curly-spacing": "off",
12
+ "react/jsx-equals-spacing": "off",
13
+ "react/jsx-first-prop-new-line": "off",
14
+ "react/jsx-indent": "off",
15
+ "react/jsx-indent-props": "off",
16
+ "react/jsx-max-props-per-line": "off",
17
+ "react/jsx-one-expression-per-line": "off",
18
+ "react/jsx-props-no-multi-spaces": "off",
19
+ "react/jsx-tag-spacing": "off",
20
+ "react/jsx-wrap-multilines": "off",
21
+ ...(includeDeprecated && {
24
22
  // Deprecated since version 7.0.0.
25
23
  // https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md#700---2017-05-06
26
24
  "react/jsx-space-before-closing": "off",
27
- }
28
- ),
25
+ }),
26
+ },
29
27
  };
package/unicorn.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  rules: {
5
+ "unicorn/empty-brace-spaces": "off",
5
6
  "unicorn/no-nested-ternary": "off",
6
7
  "unicorn/number-literal-case": "off",
7
8
  },
package/vue.js CHANGED
@@ -5,9 +5,11 @@ module.exports = {
5
5
  "vue/html-self-closing": 0,
6
6
  "vue/max-len": 0,
7
7
 
8
+ "vue/array-bracket-newline": "off",
8
9
  "vue/array-bracket-spacing": "off",
9
10
  "vue/arrow-spacing": "off",
10
11
  "vue/block-spacing": "off",
12
+ "vue/block-tag-newline": "off",
11
13
  "vue/brace-style": "off",
12
14
  "vue/comma-dangle": "off",
13
15
  "vue/comma-spacing": "off",