Socket
Socket
Sign inDemoInstall

eslint-config-prettier

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-config-prettier - npm Package Compare versions

Comparing version 1.7.0 to 2.0.0

bin/validators.js

130

bin/cli.js

@@ -7,3 +7,7 @@ #!/usr/bin/env node

const pkg = require("../package.json");
const validators = require("./validators");
const SPECIAL_RULES_URL =
"https://github.com/prettier/eslint-config-prettier#special-rules";
if (module === require.main) {

@@ -22,6 +26,5 @@ if (process.argv.length > 2 || process.stdin.isTTY) {

"",
"0: No problems found.",
"0: No automatically detectable problems found.",
"1: Unexpected error.",
"2: Conflicting rules found.",
"3: Special rules only found.",
"",

@@ -82,19 +85,60 @@ "For more information, see:",

const specialRules = Object.keys(allRules)
.filter(ruleName => allRules[ruleName] === 0)
.reduce((obj, ruleName) => {
obj[ruleName] = true;
return obj;
}, Object.create(null));
const regularRules = filterRules(
allRules,
(ruleName, value) => value === "off"
);
const optionsRules = filterRules(
allRules,
(ruleName, value) => value === 0 && ruleName in validators
);
const specialRules = filterRules(
allRules,
(ruleName, value) => value === 0 && !(ruleName in validators)
);
const flaggedRuleNames = Object.keys(config.rules).filter(ruleName => {
const value = config.rules[ruleName];
const level = Array.isArray(value) ? value[0] : value;
const isOff = level === "off" || level === 0;
return !isOff && ruleName in allRules;
});
const flaggedRules = Object.keys(config.rules)
.map(ruleName => {
const value = config.rules[ruleName];
const arrayValue = Array.isArray(value) ? value : [value];
const level = arrayValue[0];
const options = arrayValue.slice(1);
const isOff = level === "off" || level === 0;
return !isOff && ruleName in allRules ? { ruleName, options } : null;
})
.filter(Boolean);
if (flaggedRuleNames.length === 0) {
const regularFlaggedRuleNames = filterRuleNames(
flaggedRules,
ruleName => ruleName in regularRules
);
const optionsFlaggedRuleNames = filterRuleNames(
flaggedRules,
(ruleName, options) =>
ruleName in optionsRules && !validators[ruleName](options)
);
const specialFlaggedRuleNames = filterRuleNames(
flaggedRules,
ruleName => ruleName in specialRules
);
if (
regularFlaggedRuleNames.length === 0 &&
optionsFlaggedRuleNames.length === 0
) {
const baseMessage =
"No rules that are unnecessary or conflict with Prettier were found.";
const message = specialFlaggedRuleNames.length === 0
? baseMessage
: [
baseMessage,
"",
"However, the following rules are enabled but cannot be automatically checked. See:",
SPECIAL_RULES_URL,
"",
printRuleNames(specialFlaggedRuleNames)
].join("\n");
return {
stdout: "No rules that are unnecessary or conflict with Prettier were found.",
stdout: message,
code: 0

@@ -104,31 +148,26 @@ };

const regularRulesList = flaggedRuleNames
.filter(ruleName => !(ruleName in specialRules))
.sort()
.map(ruleName => `- ${ruleName}`)
.join("\n");
const specialRulesList = flaggedRuleNames
.filter(ruleName => ruleName in specialRules)
.sort()
.map(ruleName => `- ${ruleName}`)
.join("\n");
const regularMessage = [
"The following rules are unnecessary or might conflict with Prettier:",
"",
regularRulesList
printRuleNames(regularFlaggedRuleNames)
].join("\n");
const optionsMessage = [
"The following rules are enabled with options that might conflict with Prettier. See:",
SPECIAL_RULES_URL,
"",
printRuleNames(optionsFlaggedRuleNames)
].join("\n");
const specialMessage = [
"The following rules are enabled but can only be enabled in some cases.",
"It is up to you to check if they are configured correctly. See:",
"https://github.com/prettier/eslint-config-prettier#special-rules",
"The following rules are enabled but cannot be automatically checked. See:",
SPECIAL_RULES_URL,
"",
specialRulesList
printRuleNames(specialFlaggedRuleNames)
].join("\n");
const message = [
regularRulesList.length === 0 ? null : regularMessage,
specialRulesList.length === 0 ? null : specialMessage
regularFlaggedRuleNames.length === 0 ? null : regularMessage,
optionsFlaggedRuleNames.length === 0 ? null : optionsMessage,
specialFlaggedRuleNames.length === 0 ? null : specialMessage
]

@@ -140,6 +179,25 @@ .filter(Boolean)

stdout: message,
code: regularRulesList.length > 0 ? 2 : 3
code: 2
};
}
function filterRules(rules, fn) {
return Object.keys(rules)
.filter(ruleName => fn(ruleName, rules[ruleName]))
.reduce((obj, ruleName) => {
obj[ruleName] = true;
return obj;
}, Object.create(null));
}
function filterRuleNames(rules, fn) {
return rules
.filter(rule => fn(rule.ruleName, rule.options))
.map(rule => rule.ruleName);
}
function printRuleNames(ruleNames) {
return ruleNames.slice().sort().map(ruleName => `- ${ruleName}`).join("\n");
}
exports.processString = processString;

@@ -0,1 +1,18 @@

### Version 2.0.0 (2017-05-07)
- Changed/Improved: The CLI helper tool is now more helpful.
- The options of special rules are now validated if possible. If a special
rule is enabled with non-conflicting options, the CLI no longer warns about
it.
- If only special rules that cannot be automatically checked are found, the
CLI no longer exists with a non-zero exit code. Instead, it only warns about
the rules.
- Changed: The [no-confusing-arrow] is now a special rule again, since it might
conflict with recent Prettier versions.
- Removed: The `react/wrap-multilines` rule (which has been deprecated for a
while), since it was removed in eslint-plugin-react@7.
### Version 1.7.0 (2017-04-19)

@@ -2,0 +19,0 @@

@@ -10,2 +10,3 @@ "use strict";

"max-len": 0,
"no-confusing-arrow": 0,
"no-mixed-operators": 0,

@@ -37,3 +38,2 @@ quotes: 0,

"no-comma-dangle": "off",
"no-confusing-arrow": "off",
"no-extra-parens": "off",

@@ -40,0 +40,0 @@ "no-extra-semi": "off",

{
"name": "eslint-config-prettier",
"version": "1.7.0",
"version": "2.0.0",
"license": "MIT",

@@ -35,10 +35,10 @@ "author": "Simon Lydell",

"ava": "^0.19.1",
"babel-eslint": "^7.2.2",
"babel-eslint": "^7.2.3",
"dedent": "^0.7.0",
"eslint": "^3.19.0",
"eslint-config-google": "^0.7.1",
"eslint-plugin-flowtype": "^2.30.4",
"eslint-plugin-flowtype": "^2.32.1",
"eslint-plugin-prettier": "^2.0.1",
"eslint-plugin-react": "^6.10.3",
"prettier": "^1.1.0",
"eslint-plugin-react": "^7.0.0",
"prettier": "^1.3.1",
"rimraf": "^2.6.1"

@@ -45,0 +45,0 @@ },

@@ -14,5 +14,4 @@ "use strict";

"react/jsx-tag-spacing": "off",
"react/jsx-wrap-multilines": "off",
"react/wrap-multilines": "off"
"react/jsx-wrap-multilines": "off"
}
};

@@ -74,3 +74,2 @@ # eslint-config-prettier [![Build Status][travis-badge]][travis]

- 2: Conflicting rules found.
- 3: Special rules only found.

@@ -116,4 +115,14 @@ ## Example configuration

- Some require certain options. The CLI helper tool validates this.
- Some require special attention when writing code. The CLI helper tool warns
you if any of those rules are enabled, but can’t tell if anything is
problematic.
For maximum ease of use, the special rules are disabled by default. If you want
them, you need to explicitly specify them in your ESLint config.
### [curly]
**This rule requires certain options.**
If a block (for example after `if`, `else`, `for` or `while`) contains only one

@@ -159,2 +168,4 @@ statement, JavaScript allows omitting the curly braces around that statement.

**This rule requires special attention when writing code.**
Usually, Prettier takes care of following a maximum line length automatically.

@@ -168,2 +179,5 @@ However, there are cases where Prettier can’t do anything, such as for long

Keep in mind that you might have to refactor code slightly if Prettier formats
lines in a way that the `max-len` rule does not approve of.
Example configuration:

@@ -179,4 +193,56 @@

### [no-confusing-arrow]
**This rule requires certain options.**
For example, the rule could warn about this line:
```js
var x = a => 1 ? 2 : 3;
```
By default, ESLint suggests switching to an explicit return:
```js
var x = a => { return 1 ? 2 : 3; };
```
That causes no problems with Prettier.
With `{allowParens: true}`, adding parentheses is also considered a valid way to
avoid the arrow confusion:
```js
var x = a => (1 ? 2 : 3);
```
While Prettier keeps thoses parentheses, it removes them if the line is long
enough to introduce a line break:
```js
EnterpriseCalculator.prototype.calculateImportantNumbers = inputNumber =>
1 ? 2 : 3;
```
[eslint-config-airbnb] config includes `no-confusing-arrow` with the
`allowParens` option turned on by default. Since that config is very popular, it
makes sense for eslint-config-prettier to turn this rule off.
If you like this rule, it can be used just fine with Prettier as long as the
`allowParens` option is off.
Example configuration:
```json
{
"rules": {
"no-confusing-arrow": "error"
}
}
```
### [no-mixed-operators]
**This rule requires special attention when writing code.**
This rule forbids mixing certain operators, such as `&&` and `||`.

@@ -228,2 +294,4 @@

**This rule requires certain options.**
If you’d like to enforce the use of backticks rather than single or double

@@ -248,5 +316,5 @@ quotes for strings, you can enable this rule. Otherwise, there’s no need to.

- ESLint 3.19.0
- prettier 1.1.0
- eslint-plugin-flowtype 2.30.4
- eslint-plugin-react 6.10.3
- prettier 1.3.1
- eslint-plugin-flowtype 2.32.1
- eslint-plugin-react 7.0.0

@@ -320,2 +388,3 @@ Have new rules been added since those versions? Have we missed any rules? Is

[max-len]: http://eslint.org/docs/rules/max-len
[no-confusing-arrow]: http://eslint.org/docs/rules/no-confusing-arrow
[no-mixed-operators]: http://eslint.org/docs/rules/no-mixed-operators

@@ -322,0 +391,0 @@ [Prettier]: https://github.com/prettier/prettier

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc