Git Product home page Git Product logo

eslint-config-prettier's Introduction

eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.

This lets you use your favorite shareable config without letting its stylistic choices get in the way when using Prettier.

Note that this config only turns rules off, so it only makes sense using it together with some other config.

Installation

  1. Install eslint-config-prettier:

    npm install --save-dev eslint-config-prettier
    
  2. Add eslint-config-prettier to your ESLint configuration – either to eslintrc or to eslint.config.js (flat config).

    • eslintrc: Add "prettier" to the "extends" array in your .eslintrc.* file. Make sure to put it last, so it gets the chance to override other configs.

      {
        "extends": [
          "some-other-config-you-use",
          "prettier"
        ]
      }
    • eslint.config.js (flat config): Import eslint-config-prettier, and put it in the configuration array – after other configs that you want to override.

      import someConfig from "some-other-config-you-use";
      import eslintConfigPrettier from "eslint-config-prettier";
      
      export default [
        someConfig,
        eslintConfigPrettier,
      ];
  3. Finally, run the CLI helper tool to find problems in the "rules" sections of your config.

👉 Using eslint-plugin-prettier? Check out eslint-plugin-prettier’s recommended config.

Plugins

eslint-config-prettier not only turns off core rules, but also some from these plugins automatically:

ℹ️ Note: You might find guides on the Internet saying you should also extend stuff like "prettier/react". Since version 8.0.0 of eslint-config-prettier, all you need to extend is "prettier"! That includes all plugins.

eslint.config.js (flat config) plugin caveat

With flat config, you get to decide the plugin name! For example:

import typescriptEslint from "@typescript-eslint/eslint-plugin";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
  {
    plugins: {
      // You’d typically use one of the following two:
      // typescriptEslint: typescriptEslint,
      // typescriptEslint,
      // But in this example we give it another name.
      // It might be tempting to use something shorter like “ts”:
      ts: typescriptEslint, // 🚨 Don’t do this!
    },
    rules: {
      // With eslintrc, this is _always_ called:
      // @typescript-eslint/indent
      // But in eslint.config.js (flat config), the name chosen above in `plugins` is used.
      "ts/indent": "error", // 🚨 Don’t do this!
    },
  },
  eslintConfigPrettier,
];

You might expect eslint-config-prettier to turn off ts/indent, but it won’t! Because eslint-config-prettier only turns off @typescript-eslint/indent. It cannot know what you chose to call the plugin. Same thing for the CLI helper tool.

Simply stick to the official plugin names and you’ll be all good.

If you encounter a shared config that uses a non-standard plugin name, please ask them to use the standard name instead.

Excluding deprecated rules

Some of the rules that eslint-config-prettier turns off may be deprecated, or even removed from ESLint. This is perfectly fine, but if you really need to omit the deprecated and removed rules, you can do so by setting the ESLINT_CONFIG_PRETTIER_NO_DEPRECATED environment variable to a non-empty value. For example:

env ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true npx eslint-find-rules --deprecated index.js

CLI helper tool

eslint-config-prettier also ships with a little CLI tool to help you check if your configuration contains any rules that are unnecessary or conflict with Prettier. Here’s how to run it:

npx eslint-config-prettier path/to/main.js

(Change path/to/main.js to a file that exists in your project.)

What and why

Now, let’s have a look at what it does and why you might want to use it.

🚨 This eslintrc example has a conflicting rule "indent" enabled:

{
  "extends": [
    "some-other-config-you-use",
    "prettier"
  ],
  "rules": {
    "indent": "error"
  }
}

For eslintrc, while the "prettier" config can disable problematic rules in "some-other-config-you-use", it cannot touch "rules"! (That’s how ESLint works – it lets you override configs you extend.) The CLI helper tool reports that "indent" conflicts with Prettier, so you can remove it. (Which is nice – simplifying your config!)

🚨 This eslint.config.js (flat config) example also has a conflicting rule "indent" enabled:

import someConfig from "some-other-config-you-use";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
  someConfig,
  eslintConfigPrettier,
  {
    rules: {
      indent: "error",
    },
  },
];

With the new ESLint “flat config” format, you can control what things override what yourself. One way of solving the above conflict is to reorder the config objects so that eslint-config-prettier is last:

import someConfig from "some-other-config-you-use";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
  someConfig,
  {
    rules: {
      indent: "error",
    },
  },
  eslintConfigPrettier, // eslint-config-prettier last
];

However, looking at the above config might feel confusing. It looks like we enable the indent rule, but in reality it’s disabled thanks to the eslintConfigPrettier line below it. Instead you might want to actually have your own rules after eslint-config-prettier and run the CLI helper tool to find out about problems, so you can remove conflicting rules from the config file altogether (simplifying your config).

Checking multiple files

In theory you need to run the tool for every single file in your project to be 100% sure that there are no conflicting rules, because ESLint supports having different rules for different files. Usually you’ll have about the same rules for all files, so it is good enough to run the command on one file. But if you use multiple configuration files or overrides, you can provide several files to check:

npx eslint-config-prettier index.js test/index.js legacy/main.js

Exit codes

  • 0: No problems found.
  • 1: Unexpected error.
  • 2: Conflicting rules found.

ESLINT_USE_FLAT_CONFIG environment variable

Just like ESLint itself, you can control the eslint-config-prettier CLI helper tool using the ESLINT_USE_FLAT_CONFIG environment variable:

  • ESLINT_USE_FLAT_CONFIG=true: Only use eslint.config.js (flat config).
  • ESLINT_USE_FLAT_CONFIG=false: Only use eslintrc files.
  • Unset or any other value: First try eslint.config.js, then eslintrc.

Warning
For eslint.config.js (flat config), the CLI helper tool imports eslint/use-at-your-own-risk which may break at any time.

Legacy

eslint-config-prettier versions before 7.0.0 had a slightly different CLI tool that was run in a different way. For example:

npx eslint --print-config index.js | npx eslint-config-prettier-check

If you find something like that in a tutorial, this is what the command looks like in 7.0.0 or later:

npx eslint-config-prettier index.js

Special rules

There a few rules that eslint-config-prettier disables that actually can be enabled in some cases.

  • 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.
  • Some can cause problems if using eslint-plugin-prettier and --fix.

For maximum ease of use, the special rules are disabled by default (provided that you include all needed things in "extends"). If you want them, you need to explicitly specify them in your ESLint config.

These rules might cause problems if using eslint-plugin-prettier and --fix.

See the arrow-body-style and prefer-arrow-callback issue for details.

There are a couple of ways to turn these rules off:

  • Put "plugin:prettier/recommended" in your "extends". That’s eslint-plugin-prettier’s recommended config.
  • Put "prettier/prettier" in your "extends". (Yes, there’s both a rule called "prettier/prettier" and a config called "prettier/prettier".)
  • Remove them from your config or turn them off manually.

It doesn’t matter which approach you use. "plugin:prettier/recommended" is probably the easiest.

Note: The CLI tool only reports these as problematic if the "prettier/prettier" rule is enabled for the same file.

These rules are safe to use if you don’t use eslint-plugin-prettier. In other words, if you run eslint --fix and prettier --write as separate steps.

This rule requires certain options.

If a block (for example after if, else, for or while) contains only one statement, JavaScript allows omitting the curly braces around that statement. This rule enforces if or when those optional curly braces should be omitted.

If you use the "multi-line" or "multi-or-nest" option, the rule can conflict with Prettier.

For example, the "multi-line" option allows this line:

if (cart.items && cart.items[0] && cart.items[0].quantity === 0) updateCart(cart);

However, Prettier might consider the line too long and turn it into the following, which the "multi-line" option does not allow:

if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
  updateCart(cart);

If you like this rule, it can be used just fine with Prettier as long as you don’t use the "multi-line" or "multi-or-nest" option.

Example ESLint configuration:

{
  "rules": {
    "curly": ["error", "all"]
  }
}

(The following applies to @typescript-eslint/lines-around-comment as well.)

This rule can be used with certain options.

This rule requires empty lines before and/or after comments. Prettier preserves blank lines, with two exceptions:

  • Several blank lines in a row are collapsed into a single blank line. This is fine.
  • Blank lines at the beginning and end of blocks, objects and arrays are always removed. This may lead to conflicts.

By default, ESLint requires a blank line above the comment is this case:

if (result) {

  /* comment */
  return result;
}

However, Prettier removes the blank line:

if (result) {
  /* comment */
  return result;
}

If you like this rule, it can be used just fine with Prettier as long as you add some extra configuration to allow comments at the start and end of blocks, objects and arrays.

Example ESLint configuration:

{
  "rules": {
    "lines-around-comment": [
      "error",
      {
        "beforeBlockComment": true,
        "afterBlockComment": true,
        "beforeLineComment": true,
        "afterLineComment": true,
        "allowBlockStart": true,
        "allowBlockEnd": true,
        "allowObjectStart": true,
        "allowObjectEnd": true,
        "allowArrayStart": true,
        "allowArrayEnd": true
      }
    ]
  }
}

max-len (deprecated)

(The following applies to vue/max-len as well.)

This rule requires special attention when writing code.

Usually, Prettier takes care of following a maximum line length automatically. However, there are cases where Prettier can’t do anything, such as for long strings, regular expressions and comments. Those need to be split up by a human.

If you’d like to enforce an even stricter maximum line length policy than Prettier can provide automatically, you can enable this rule. Just remember to keep max-len’s options and Prettier’s printWidth option in sync.

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 ESLint configuration:

{
  "rules": {
    "max-len": ["error", {"code": 80, "ignoreUrls": true}]
  }
}

no-confusing-arrow (deprecated)

This rule requires certain options.

For example, the rule could warn about this line:

var x = a => 1 ? 2 : 3;

With {allowParens: true} (the default since ESLint 6.0.0), adding parentheses is considered a valid way to avoid the arrow confusion:

var x = a => (1 ? 2 : 3);

While Prettier keeps those parentheses, it removes them if the line is long enough to introduce a line break:

EnterpriseCalculator.prototype.calculateImportantNumbers = inputNumber =>
  1 ? 2 : 3;

With {allowParens: false}, ESLint instead suggests switching to an explicit return:

var x = a => { return 1 ? 2 : 3; };

That causes no problems with Prettier.

If you like this rule, it can be used just fine with Prettier as long as the allowParens option is off.

Example ESLint configuration:

{
  "rules": {
    "no-confusing-arrow": ["error", { "allowParens": false }]
  }
}

(Note: The CLI helper tool considers {allowParens: true} to be the default, which is the case since ESLint 6.0.0. The tool will produce a warning if you use the default even if you use an older version of ESLint. It doesn’t hurt to explicitly set {allowParens: false} even though it is technically redundant. This way you are prepared for a future ESLint upgrade and the CLI tool can be kept simple.)

no-mixed-operators (deprecated)

This rule requires special attention when writing code.

This rule forbids mixing certain operators, such as && and ||.

For example, the rule could warn about this line:

var foo = a + b * c;

The rule suggests adding parentheses, like this:

var foo = a + (b * c);

However, Prettier removes many “unnecessary” parentheses, turning it back to:

var foo = a + b * c;

If you want to use this rule with Prettier, you need to split the expression into another variable:

var bar = b * c;
var foo = a + bar;

Keep in mind that Prettier prints some “unnecessary” parentheses, though:

var foo = (a && b) || c;

Example ESLint configuration:

{
  "rules": {
    "no-mixed-operators": "error"
  }
}

no-tabs (deprecated)

This rule requires certain options.

This rule disallows the use of tab characters. By default the rule forbids all tab characters. That can be used just fine with Prettier as long as you don’t configure Prettier to indent using tabs.

Luckily, it’s possible to configure the rule so that it works regardless of whether Prettier uses spaces or tabs: Set allowIndentationTabs to true. This way Prettier takes care of your indentation, while the no-tabs takes care of potential tab characters anywhere else in your code.

Example ESLint configuration:

{
  "rules": {
    "no-tabs": ["error", {"allowIndentationTabs": true}]
  }
}

This rule requires special attention when writing code.

This rule disallows confusing multiline expressions where a newline looks like it is ending a statement, but is not.

For example, the rule could warn about this:

var hello = "world"
[1, 2, 3].forEach(addNumber)

Prettier usually formats this in a way that makes it obvious that a semicolon was missing:

var hello = "world"[(1, 2, 3)].forEach(addNumber);

However, there are cases where Prettier breaks things into several lines such that the no-unexpected-multiline conflicts.

const value = text.trim().split("\n")[position].toLowerCase();

Prettier breaks it up into several lines, though, causing a conflict:

const value = text
  .trim()
  .split("\n")
  [position].toLowerCase();

If you like this rule, it can usually be used with Prettier without problems, but occasionally you might need to either temporarily disable the rule or refactor your code.

const value = text
  .trim()
  .split("\n")
  // eslint-disable-next-line no-unexpected-multiline
  [position].toLowerCase();

// Or:

const lines = text.trim().split("\n");
const value = lines[position].toLowerCase();

Note: If you do enable this rule, you have to run ESLint and Prettier as two separate steps (and ESLint first) in order to get any value out of it. Otherwise Prettier might reformat your code in such a way that ESLint never gets a chance to report anything (as seen in the first example).

Example configuration:

{
  "rules": {
    "no-unexpected-multiline": "error"
  }
}

quotes (deprecated)

(The following applies to babel/quotes and @typescript-eslint/quotes as well.)

This rule requires certain options and certain Prettier options.

Usually, you don’t need this rule at all. But there are two cases where it could be useful:

  • To enforce the use of backticks rather than single or double quotes for strings.
  • To forbid backticks where regular strings could have been used.

Enforce backticks

If you’d like all strings to use backticks (never quotes), enable the "backtick" option.

Example ESLint configuration:

{
  "rules": {
    "quotes": ["error", "backtick"]
  }
}

Forbid unnecessary backticks

In the following example, the first array item could have been written with quotes instead of backticks.

const strings = [
  `could have been a regular string`,
  `
    multiple
    lines
  `,
  `uses ${interpolation}`,
  String.raw`\tagged/`,
];

If you’d like ESLint to enforce `could have been a regular string` being written as either "could have been a regular string" or 'could have been a regular string', you need to use some specific configuration. The quotes rule has two options, a string option and an object option.

  • The first (string) option needs to be set to "single" or "double" and be kept in sync with Prettier’s singleQuote option.
  • The second (object) option needs the following properties:
    • "avoidEscape": true to follow Prettier’s string formatting rules.
    • "allowTemplateLiterals": false to disallow unnecessary backticks.
Example double quote configuration

ESLint:

{
  "rules": {
    "quotes": [
      "error",
      "double",
      { "avoidEscape": true, "allowTemplateLiterals": false }
    ]
  }
}

Prettier (this is the default, so adding this is not required):

{
  "singleQuote": false
}
Example single quote configuration

ESLint:

{
  "rules": {
    "quotes": [
      "error",
      "single",
      { "avoidEscape": true, "allowTemplateLiterals": false }
    ]
  }
}

Prettier:

{
  "singleQuote": true
}

This rule can be used with certain options.

This rule will automatically fix the indentation of multiline string templates, to keep them in alignment with the code they are found in. A configurable whitelist is used to ensure no whitespace-sensitive strings are edited.

Prettier deals with:

  • HTML
  • CSS
  • GraphQL
  • markdown

Using various tags, functions and comments.

unicorn/template-indent by default formats some of the same tagged templates, which can cause conflicts. For example, the rule and Prettier disagree about indentation in ternaries:

condition
  ? null
  : html`
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui
        mauris.
      </p>
    `;

If you like this rule, it can be used just fine with Prettier as long as you configure the rule to not deal with the same templates as Prettier.

Example ESLint configuration:

{
  "rules": {
    "unicorn/template-indent": [
      "error",
      {
        "tags": [
          "outdent",
          "dedent",
          "sql",
          "styled"
        ],
        "functions": [
          "dedent",
          "stripIndent"
        ],
        "selectors": [],
        "comments": [
          "indent"
        ]
      }
    ]
  }
}

Note: If you use "selectors", the CLI helper tool cannot detect if your selectors might cause conflicts.

This rule requires certain options.

This rule enforces whether elements should be self-closing or not.

Prettier generally preserves the way you wrote your elements:

<div />
<div></div>
<MyComponent />
<MyComponent></MyComponent>
<svg><path d="" /></svg>
<svg><path d=""></path></svg>

But for known void HTML elements, Prettier always uses the self-closing style. For example, <img> is turned into <img />.

If you like this rule, it can be used just fine with Prettier as long as you set html.void to "any".

Example ESLint configuration:

{
  "rules": {
    "vue/html-self-closing": [
      "error",
      {
        "html": {
          "void": "any"
        }
      }
    ]
  }
}

Other rules worth mentioning

These rules don’t conflict with Prettier, but have some gotchas when used with Prettier.

This rule forbids using JavaScript’s confusing comma operator (sequence expressions). This piece of code is not doing what it looks like:

matrix[4, 7];

Prettier adds parentheses to the above to make it clear that a sequence expression is used:

matrix[(4, 7)];

However, the no-sequences rule allows comma operators if the expression sequence is explicitly wrapped in parentheses. Since Prettier automatically wraps them in parentheses, you might never see any warnings from ESLint about comma operators.

Ending up with an accidental sequence expression can easily happen while refactoring. If you want ESLint to catch such mistakes, it is recommended to forbid sequence expressions entirely using no-restricted-syntax (as mentioned in the no-sequences documentation):

{
  "rules": {
    "no-restricted-syntax": ["error", "SequenceExpression"]
  }
}

If you still need to use the comma operator for some edge case, you can place an // eslint-disable-next-line no-restricted-syntax comment on the line above the expression. no-sequences can safely be disabled if you use the no-restricted-syntax approach.

You can also supply a custom message if you want:

{
  "rules": {
    "no-restricted-syntax": [
      "error",
      {
        "selector": "SequenceExpression",
        "message": "The comma operator is confusing and a common mistake. Don’t use it!"
      }
    ]
  }
}

Contributing

See package.json for the exact versions of ESLint, Prettier and ESLint plugins that eslint-config-prettier has been tested with.

Have new rules been added since those versions? Have we missed any rules? Is there a plugin you would like to see exclusions for? Open an issue or a pull request!

If you’d like to add support for eslint-plugin-foobar, this is how you’d go about it:

First, add rules to index.js:

"foobar/some-rule": "off"

Then, create test-lint/foobar.js:

/* eslint-disable quotes */
"use strict";

// Prettier does not want spaces before the parentheses, but
// `plugin:foobar/recommended` wants one.
console.log();

test-lint/foobar.js must fail when used with eslint-plugin-foobar and eslint-plugin-prettier at the same time – until eslint-config-prettier is added to the ESLint config. The file should be formatted according to Prettier, and that formatting should disagree with the plugin.

Finally, you need to mention the plugin in several places:

  • Add eslint-plugin-foobar to the "devDependencies" field in package.json.
  • Make sure that at least one rule from eslint-plugin-foobar gets used in .eslintrc.base.js and eslint.base.config.js.
  • Add it to the lists of supported plugins in this README.md.

When you’re done, run npm test to verify that you got it all right. It runs several other npm scripts:

  • "test:prettier" checks that Prettier has been run on all files.
  • "test:eslint" makes sure that the files in test-lint/ pass ESLint when the exclusions from eslint-config-prettier are used. It also lints the code of eslint-config-prettier itself.
  • "test:lint-verify-fail" is run by a test in test/lint-verify-fail.test.js.
  • "test:lint-rules" is run by a test in test/rules.test.js.
  • "test:jest" runs unit tests that check a number of things:
    • That eslint-plugin-foobar is mentioned in all the places shown above.
    • That no unknown rules are turned off. This helps catching typos, for example.
    • That the CLI works.
  • "test:cli-sanity" and "test:cli-sanity-warning" are sanity checks for the CLI.

License

MIT.

eslint-config-prettier's People

Contributors

0xr avatar bakkot avatar bartocc avatar dependabot-preview[bot] avatar dependabot[bot] avatar fdawgs avatar fisker avatar formatlos avatar hoishin avatar j-f1 avatar joecritch avatar jounqin avatar lydell avatar mauricedb avatar miangraham avatar michalsnik avatar mrtnzlml avatar murkrage avatar nfriedly avatar nstepien avatar o-az avatar pleunv avatar pvdlg avatar regseb avatar silvenon avatar sudo-suhas avatar tibdex avatar ttionya avatar xcatliu avatar ybiquitous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-config-prettier's Issues

Cannot convert undefined or null to object

In the extends array, if I write it like this

    "extends": [
        "eslint:recommended",
        "prettier"
    ],

This error shows up: Cannot convert undefined or null to object Referenced from: **/.eslintrc

However when I write it like this:

    "extends": [
        "eslint:recommended",
        "plugin:prettier"
    ],

it works fine. Is that valid syntax or will that prevent it from working properly? Thanks!

eslint rule contradiction with prettier

When I write this code:

const { caretPosition: [selectionStart, selectionEnd] } = this.state;

the prettier reformats it to

const {
  caretPosition: [selectionStart, selectionEnd]
} = this.state;

live demo

But the eslint wants it to be a single line.

image

image

package.json

...
    "babel-eslint": "^7.2.3",
...
    "eslint": "^4.13.1",
    "eslint-config-prettier": "^2.9.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-prettier": "^2.4.0",
    "eslint-plugin-react": "^7.5.1",
...
    "prettier": "^1.9.2",

How to remove semi

I dont like semi ,but it in default;
When i want to add rule to ban semi , then i cant pass the check

{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module", 
    "allowImportExportEverywhere": true 
  },
  "extends": [
    "standard",    
    "eslint:recommended",
    "plugin:react/recommended",
    "standard-react",
    "prettier",
    "prettier/react",
    "prettier/standard"
  ], 
  "rules": {
    "semi":"error",
    "no-extra-semi":"error",
    "prettier/prettier": "error",
    "react/prop-types": 0 
  },
  "plugins": [
    "html",
    "react",
    "prettier",
    "standard"
  ]
}

qq20171128-142646

Conflict with recommended configuration of prettier

As specified by https://prettier.io/docs/en/eslint.html I used

{
  "extends": ["plugin:prettier/recommended"]
}

with

  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-eslint": "^10.0.1",
    "babel-preset-flow": "^6.23.0",
    "eslint": "^5.12.1",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-config-prettier": "^3.6.0",
    "eslint-plugin-flowtype": "^3.2.1",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-prettier": "^3.0.1",
    "flow-bin": "^0.91.0",
    "flow-typed": "^2.5.1",
    "prettier": "1.16.0"
  }

and eslintrc

{
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "parser": "babel-eslint",
  "plugins": ["flowtype"],
  "extends": [
    "plugin:prettier/recommended",
    "plugin:flowtype/recommended",
    "prettier/babel",
    "prettier/flowtype"
  ],
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "rules": {
    "indent": ["error", "tab"],
    "linebreak-style": ["error", "unix"],
    "quotes": ["error", "single"],
    "semi": ["error", "always"],
    "flowtype/no-types-missing-file-annotation": 0
  }
}

The problem is that eslint's indent rule expects a tab and prettier's recommended configuration expects two spaces. This leads to a conflict. To be clear, the eslint website specifies only the use of "extends": ["plugin:prettier/recommended"] only. When removing this and using prettier extension with airbnb it works just fine.

conflicts with standard/computed-property-even-spacing

I'm using eslint-config-prettier together with eslint-config-prettier-standard which works great except for this:

prettier wants

    const { whatever } = loooooooooooooooooooooooong[
      something
    ].some.thiiiiiiiiiiiiing[0]

while standard wants

    const { whatever } = loooooooooooooooooooooooong[something].some.thiiiiiiiiiiiiing[0]

I wonder if this is due to computed-property-even-spacing not being turned off.

eslint-config-prettier-check reports "No rules that are unnecessary or conflict with Prettier were found."

prettier conflicts with no-unexpected-multiline

This scenario is relevant when a shareable config like airbnb-base is combined with prettier. If the rule no-unexpected-multiline is enabled, it ends up resulting in a error which can only be resolved by switching off the rule.

.eslintrc.yml

extends: prettier
plugins:
  - prettier
parserOptions:
  ecmaVersion: 8
  sourceType: script
rules:
  no-undef: off
  no-unused-vars: off
  no-unexpected-multiline: error
  prettier/prettier:
    - error
    -
      trailingComma: none
      singleQuote: true
      printWidth: 80
      tabWidth: 4

code snippet

const value =
    Array.isArray(param) && spread
        ? getInstance()
              [methodName](...param)
              .toJSON()
        : getInstance()
              [methodName](param)
              .toJSON();

Eslint output:

  4:15  error  Unexpected newline between object and [ of property access  no-unexpected-multiline
  7:15  error  Unexpected newline between object and [ of property access  no-unexpected-multiline

If I fix the errors:

  3:24  error  Insert `⏎··············`  prettier/prettier
  5:24  error  Insert `⏎··············`  prettier/prettier

How to tell it not to accept TypeScript syntax in JavaScript files?

I have some files that are not TypeScript, but Prettier has no problem formatting them. When I install eslint-config-prettier, ESLint also is not telling me about syntax errors on TypeScript syntax. I'd like for ESLint to tell me that any Type-related stuff is a syntax error in js or jsx files.

airbnb rule "no-unexpected-multiline" not covered

Hi there,

I ran into a small problem. For the following eslint config:

{
  "extends": ["airbnb-base", "prettier"]
}

and this non-pretty code:

const objectWithFunctions = {
  foo: (value) => Promise.resolve(value)
};

const functionThatReturnsObject = () => objectWithFunctions;

const someVariableThatGivesUsTheKey = 'foo';

functionThatReturnsObject()[someVariableThatGivesUsTheKey]('hello world').then(res => console.log(res))

Prettier outputs the following:

const objectWithFunctions = {
  foo: value => Promise.resolve(value),
};

const functionThatReturnsObject = () => objectWithFunctions;

const someVariableThatGivesUsTheKey = 'foo';

functionThatReturnsObject()
  [someVariableThatGivesUsTheKey]('hello world')
  .then(res => console.log(res));

and ESLint complains with the following:

error  Unexpected newline between object and [ of property access  no-unexpected-multiline

Not sure if this is an issue with the config here or maybe even with Prettier itself. If it's something with the config I could help out with a PR.

Using:

autoFixOnSave alternates between correct and wrong indentation

I have quite strange error. I set eslint.autoFixOnSave to true. When I save a file once it formats my code successfully:

image

When I save it again it messes up the indentation.

image

When I save a 3rd time it fixes the indentation again as in screenshot 1 and so on.

How can this happen?
This is my .eslintrc.json:

{
  "extends": "prettier",
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": 2017
  },
  "env": {
    "es6": true,
    "node": true
  },
  "plugins": [
    "prettier"
  ],
  "rules": {
    "prettier/prettier": [
      "error",
      {
        "semi": false,
        "printWidth": 120
      }
    ]
  }
}

Edit: I recorded a video with the strange behaviour:

eslint-problem

Conflict with import/newline-after-import

I am currently using prettier through eslint run and there is a (tricky) rule that seems to break.

I am using JS without semicolons which implies declaration of IIFE with a semicolon before parenthesis. Then I have the following case:

  • Ok for prettier, not ok for eslint that will consider that first line is ending after the ";" and then eslint returns an "import/newline-after-import" error
const EventStore = require('../service/eventStore')

;(async () => {
  const eventBus = await EventBus.getInstance()
  eventBus.stanConnection.on('connect', registerCommandHandlers)
})()
  • Ok for eslint, not ok for prettier that returns a "Delete ↵" on line 3.
const EventStore = require('../service/eventStore')
;

(async () => {
  const eventBus = await EventBus.getInstance()
  eventBus.stanConnection.on('connect', registerCommandHandlers)
})()

Could not find a suitable solution for this particular use case.

Confusion about curly

With [email protected] we were successfully configuring ESLint with "curly": ["error", "all"]. After f7a4b4e, eslint-config-prettier-check now exits with an error code and this message:

The following rules can be enabled in some cases. See:
https://github.com/prettier/eslint-config-prettier#special-rules

- curly

The readme still says this is a valid rule config:

{
  "rules": {
    "curly": ["error", "all"]
  }
}

Should eslint-config-prettier-check really be failing with this config?

4 space tab rule conflicts with long a ? b : c statements

For example
image
but with 28 spaces:
image

Environment

  • ESLint Version: 5.6.1
  • Prettier Version: 1.14.3
  • eslint-config-prettier: "3.1.0",
  • Node Version: 10.11.0
  • npm Version: 6.4.1

Full configuration:

{
    "env": {
        "node": true,
        "es6": true
    },
    "extends": [
        "airbnb-base",
        "plugin:node/recommended",
        "prettier"
    ],
    "parser": "esprima",
    "plugins": [
        "node",
        "prettier"
    ],
    "root": true,
    "rules": {
        "indent": ["error", 4, { "SwitchCase": 1 }],
        "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
        "no-underscore-dangle": 0,
        "node/exports-style": ["error", "module.exports"],
        "prettier/prettier": ["error", {
            "singleQuote": true,
            "tabWidth": 4
        }]
    }
}

And for .prettierrc

{
    "singleQuote": true,
    "tabWidth": 4
}

Source code causing the issue.*

Any code that has a long a ? b : c statement will trigger the conflict:

            new PageComponent({
                tool: 'textbox',
                top: 380,
                left: 80,
                width: 380,
                height: 100,
                properties: {
                    question: options.question,
                    solution: solutions[0],
                    validation:
                        solutions.length > 1
                            ? `// ignoreCaseMatch ${JSON.stringify([
                                `^(?:${escaped.join('|')})$`
                            ])}`
                            : '// ignoreCaseEqual'
                }
            })

This runs In WebStorm with the following config:

image

But also using grunt-eslint configured in grunfile.js as follows:

        eslint: {
            files: [
                '*.js',
                'templates/*.es6',
                'src/js/**/*.es6',
                'test/**/*.es6'
            ],
            options: {
                config: '.eslintrc'
            }
        },

Example configuration has unnecessary options

https://github.com/prettier/eslint-config-prettier#example-configuration

Currently the manual is showing an example config that recommends redundant configuration options.

This config is equivalent to what is in the manual:

{
  "extends": [
    "standard",
    "plugin:flowtype/recommended",
    "plugin:react/recommended",
    "prettier",
    "prettier/flowtype",
    "prettier/react",
    "prettier/standard"
  ],
  "plugins": [
    "prettier"
  ],
  "rules": {
    "prettier/prettier": "error"
  }
}

To test this you can set up a blank project and install the required dependencies.

yarn init -y && \
yarn add --dev \
  babel-eslint \
  eslint@^4 \
  eslint-config-prettier \
  eslint-config-standard \
  eslint-plugin-flowtype \
  eslint-plugin-import \
  eslint-plugin-node \
  eslint-plugin-prettier \
  eslint-plugin-promise \
  eslint-plugin-react \
  eslint-plugin-standard \
  prettier

Now you can view the final exported config:

npx eslint --print-config .eslint.json > final.json

If you compare that output with the output generated by the example configuration it is exactly the same.

How to add brace-style rules to prettier?

So I want to use stroustrup for my brace-style, I updated my .eslintrc file as per below but prettier keeps complaining and I can only suppress the prettier/prettier rule in WebStorm.

  rules: {

    ...

    'brace-style': [
      'error',
      'stroustrup',
      {
        'allowSingleLine': true
      }
    ],

    'prettier/prettier': [
      'error',
      {
        singleQuote: true,
        trailingComma: 'all',
      },
    ],
  },

It keeps complaining about this:

  if (isMeow()) {
    meow();
  }
  else {
    bork();
  }

Thanks for reading my question 👍

🍰

semi error in Vue Template

eslint-config-prettier 3.3.0

I use vim-prettier will generate semi automatically , but cause error ,how do I configure it?

Input:

<com @click="$emit('click');"></comp>

Output:

error  Delete `;`  prettier/prettier

Expected behavior:

No error;

unicorn/number-literal-case conflict with Prettier

[I'm pretty sure this issue goes here, and not with prettier/prettier-eslint, but please let me know otherwise]

When using both prettier/prettier-eslint and prettier-eslint-config-prettier, ESLint's Autofix-On-Save converts hex values to uppercase automatically, and then complains that they aren't lowercase, with e.g. Replace `FFFFFF` with `ffffff` (prettier/prettier).

Using ESLint VSCode Plugin, with { "eslint.autoFixOnSave": true }, and the following configs:

.eslintrc

{
	"env": {
		"browser": true,
		"node": true
	},
	"extends": [
		"airbnb",
		"plugin:promise/recommended",
		"plugin:unicorn/recommended",
		"plugin:prettier/recommended",
		"prettier/react"
	],
	"plugins": ["import", "promise", "unicorn"],
	"rules": {
		"prettier/prettier": "error",
		"quotes": ["error", "backtick"],
		"no-console": "off",
		"no-plusplus": "off",
		"prefer-const": "error",
		"prefer-template": "error",
		"import/first": "off",
		"unicorn/filename-case": "off",
		"radix": "off",
		"import/prefer-default-export": "off",
		"no-use-before-define": "off",
		"no-underscore-dangle": "off",
		"class-methods-use-this": "off"
	}
}

.prettierrc

{
	"printWidth": 72,
	"tabWidth": 4,
	"useTabs": true,
	"semicolons": true,
	"singleQuote": false,
	"trailingComma": "es5",
	"bracketSpacing": true,
	"arrowParens": "always"
}

Build failing at plugin:vue/no-layout-rules

While trying to compile my project, I get the following error

Module build failed (from ./node_modules/eslint-loader/index.js):
Error: Failed to load config "plugin:vue/no-layout-rules" to extend from.
Referenced from Referenced from: /node_modules/eslint-config-prettier/vue.js

project build from few days back works fine. Its the latest build which is failing. Any suggestions

max-len rule not being taken into account

I have the following
.eslintrc:

{
  "extends": [
    "airbnb",
    "plugin:prettier/recommended",
    "prettier/react"
  ],
  "env": {
    "es6": true,
    "node": true,
    "jest": true
  },
  "rules": {
    "import/no-unresolved": [
      "error",
      { "ignore": ["client/build/asset-manifest.json"] }
    ],
    "max-len": ["error", { "code": 120 }],
    "import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": [
          "**/*.test.js"
        ]
      }
    ]
  }
}

and .prettierrc:

semi: true
trailingComma: es5
singleQuote: true
printWidth: 120

Unfortunately. When I run eslint . --ext .js,.jsx i get a bunch of errors like:

  232:1  error  Line 232 exceeds the maximum line length of 100  max-len

Why is the max-len rule looking for lines > 100 chars, and not 120?

Possibly add support for standard

Prettier can emit this:

function test() {
  const {quantity = quantities[cartType], delta = 0} = changes[
    cartType
  ] || {};
}

which seems to violate the standard/computed-property-even-spacing rule.

Error in Node v6 after updating `eslint-config-prettier` to v3.1.0

After updating from v3.0.1 to v3.1.0, I see the following behavior in Node v6 with its bundled npm (v3.10.10):

echo '{"rules": {}}' | ./node_modules/.bin/eslint-config-prettier-check

Unexpected error TypeError: Cannot read property 'filter' of undefined
    at processString (/opt/code/demo/node_modules/eslint-config-prettier/bin/cli.js:78:7)
    at getStdin.then.string (/opt/code/demo/node_modules/eslint-config-prettier/bin/cli.js:37:22)
    at process._tickCallback (internal/process/next_tick.js:109:7)

Updating npm and reinstalling eslint-config-prettier-check resolves the problem. For project's using Travis CI, adding the following to .travis.yml does the trick:

before_install:
- npm install -g npm@latest

The problem doesn't occur in Node v8 or v10 (which come bundled with newer versions of npm). The problem also doesn't occur with v3.0.1 or earlier of eslint-config-prettier, even when using Node v6 and its bundled npm v3.10.10.

The root of the problem is that the metadata for v3.1.0 in https://registry.npmjs.org/eslint-config-prettier doesn't include the files key, whereas the metadata for previous versions do. The exclusion of the files key from registry metadata is consistent across other projects starting in late August. I created an npm support topic asking if this change was intentional, but it didn't receive any responses.

The reason the lack of the files key in the registry metadata results in an error when eslint-config-prettier is installed via npm v3.10.10 is because older versions of npm generate node_modules/<package>/package.json based on the metadata from https://registry.npmjs.org/eslint-config-prettier (which is missing the files key). Newer versions of npm instead create that file based on the package.json inside of https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-3.1.0.tgz (which includes the files key).

Note that this problem only presents itself when eslint-config-prettier is installed as a dependency inside of another project. That's why this project's Travis build for Node v6 isn't failing.

Use with create-react-app

Hello,

I think this is a great project - been trying to get a handle on using prettier with eslint. I was already using the Prettier extension in my project, and found the default formatting to work well. I came across this article on Medium and ended up looking into your plugin more closely, it seemed like a great way to manage everything.

Unfortunately, when I added this package along with eslint-plugin-react and eslint-plugin-standard (and the example .eslintrc from eslint-config-prettier's README) to my existing create-react-app project, my JSX code went from this:

        }) => (
          <Form
            id={this.state.requiredFieldsProps.formId}
            onSubmit={handleSubmit}
          >
            <Row>
              <Col xs="12" sm="6">
                <FormGroup>
                  <Label for={this.state.requiredFieldsProps.fields.lob.name}>
                    Foo
                  </Label>
                  <Field
                    component={Select}
                    name={this.state.requiredFieldsProps.fields.lob.name}
                    id={this.state.requiredFieldsProps.fields.lob.name}
                    change={handleChange}
                    value={values.lob}
                    options={requiredFieldsDropdowns.lob.options}
                  />

to this:

        }) => ( <
          Form id = {
            this.state.requiredFieldsProps.formId
          }
          onSubmit = {
            handleSubmit
          } >
          <
          Row >
          <
          Col xs = "12"
          sm = "6" >
          <
          FormGroup >
          <
          Label
          for = {
            this.state.requiredFieldsProps.fields.lob.name
          } > {
            this.state.requiredFieldsProps.fields.lob.label
          } <
          /Label> <
          Field component = {
            Select
          }
          name = {
            this.state.requiredFieldsProps.fields.lob.name
          }
          id = {
            this.state.requiredFieldsProps.fields.lob.name
          }
          change = {
            this.handleSelectChange
          }
          value = {
            values.lob
          }
          options = { 
            this.state.requiredFieldsDropdowns.lob
          }
          /> <

Obviously, this isn't very readable and actually causes linter errors. What's really odd to me is that prior to adding these packages, I was just using the prettier extension with no modifications and it was formatting my JSX nicely, as well as handling indentation and semicolons, etc.
I tried adding a .prettierrc with settings like:

{ "useTabs": false, "printWidth": 80, "tabWidth": 2, "singleQuote": true, "trailingComma": "none", "jsxBracketSameLine": false }

but that didn't seem to help.
I'm guessing that CRA has some default eslint config that it's trying to apply which conflicts with the settings Prettier and the packages/plugins I've installed are conflicting with. Any ideas on how I might get this all to work together? I'm trying to come up with a flexible, simple linter setup that can be used on a project with several developers using different code editors and this seems like a really promising solution, if I can work out the kinks.

Thanks!

The "quotes" rule can be used to force unnecessary template literals into strings

From prettier/prettier#5120 by @npetruzzelli:

module.exports = {
    "rules": {
        quotes: ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
        "prettier/prettier": ["error", { singleQuote: true }]
    }
}

// OR


module.exports = {
    "rules": {
        quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: false }],
        "prettier/prettier": ["error", { singleQuote: false }]
    }
}

Will work. The trick is to keep quotes in sync with singleQuote's value. This makes ESLint turn `string` into "string" or 'string'.

We need to document this, and make sure that the CLI helper tool is smart about this case.

Disable `arrow-body-style` rule

When using the arrow-body-style rule along with the Prettier, the output can result in invalid code.
Here's a thread with a working example: airbnb/javascript#1987

Since prettier handles arrow style well, can we switch this rule off in this repo?

arrow-body-style config that results in invalid code:

['error', 'as-needed', { requireReturnForObjectLiteral: false, }],

code

const foo = (paramA, paramB, paramC) => {
  return Object.keys(paramB.prop.nestedProp[0])
    .filter(attribute => paramC.includes(attribute))
    .map(attribute => {
      return Object.keys(paramB.prop.nestedProp[0][attribute]).map(
        attributeKey => {
          return {
            key: `${paramA.name} ${paramB.type} ${attribute} ${attributeKey}`,
            value: paramB.prop.nestedProp[0][attribute][attributeKey],
          }
        }
      )
    })
}

eslint config:

{
  "parser": "babel-eslint",
  "plugins": ["prettier", "react", "jest"],
  "env": {
    "browser": true,
    "node": true,
    "jasmine": true,
    "jest/globals": true
  },
  "parserOptions": {
    "ecmaVersion": 2017,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "settings": {
    "import/resolver": {
      "webpack": {
        "config": "webpack.common.js"
      }
    }
  },
  "rules": {},
  "extends": ["airbnb", "plugin:prettier/recommended"]
}

React exclusion rules don't seem to work

It still gives me formatting errors, even though I thought I'd followed all the instructions:

/Users/stian/src/FROG/frog/imports/ui/Activities.jsx
  39:9  error  Missing parentheses around multilines JSX  react/jsx-wrap-multilines

Here is my entire .eslintrc file (many of the items should be unnecessary with this config

{
	'plugins': ['flowtype', 'prettier'],
	"globals": {
		"window": true
	},
	'rules': {

		'import/extensions': 'off',
		'import/no-extraneous-dependencies': 'off',
		'import/no-unresolved': 'off',
		'no-underscore-dangle': 'off',
		'no-unused-vars': ["error", { "varsIgnorePattern": "_" }],
		'import/prefer-default-export': 'off',
		'prefer-template': 'off',
		'react/prop-types': 'off',
		'react/no-multi-comp': 'off',
		'jsx-a11y/href-no-hash': 'off',
		"react/jsx-filename-extension": 'off',
		'react/jsx-closing-bracket-location': 'off',
		'react/jsx-indent-props': 'off',
		'react/jsx-indent': 'off',
		'no-return-assign': 'off',
		'no-throw-literal': 'off',
		'no-use-before-define': 'off',
		'no-param-reassign': ['error', { 'props': false }],
		"prettier/prettier": ['warn', {'singleQuote': true}],
		'no-nested-ternary': 'off',
		'no-constant-condition': 'off'

	},
	"parserOptions": {
		"ecmaVersion": 2016,
		"sourceType": "module",
		"ecmaFeatures": {
			"jsx": true
		}
	},
	"env": {
		"es6": true,
		"node": true
	},
	'extends': ['airbnb', 'plugin:flowtype/recommended', 'prettier', 'prettier/react' ]
}

Thank you!

Tests fail on windows

If I run the tests on windows, I get a couple of errors:

λ yarn test
yarn run v1.2.1
$ npm run test:lint && npm run test:ava && npm run test:cli-sanity

> [email protected] test:lint E:\Projects\repos\eslint-config-prettier
> eslint .

> [email protected] test:ava E:\Projects\repos\eslint-config-prettier
> ava

  23 passed
  2 failed

  lint-verify-fail » test-lint/ causes errors without eslint-config-prettier
  E:\Projects\repos\eslint-config-prettier\test\lint-verify-fail.js:21
   20:   t.is(
   21:     output.length,
   22:     ruleFiles.length,
  Error thrown in test:
  TypeError {
    message: 'Cannot read property \'length\' of null',
  }

  rules » There are no unknown rules
  E:\Projects\repos\eslint-config-prettier\test\rules.js:127
   126:
   127:   output[0].messages.forEach(message => {
   128:     t.notRegex(message.message, /rule\s+'[^']+'.*not found/);
  Error thrown in test:
  TypeError {
    message: 'Cannot read property \'0\' of null',
  }

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:ava: `ava`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test:ava script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\suhas.karanth\AppData\Roaming\npm-cache\_logs\2017-11-01T07_36_09_833Z-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This only affects contributors on windows as the tests run fine on travis. cross-spawn might fix this issue.

Disable rule suggestions

In a fairly large codebase I've found these rules to be unnecessary/conflicting when using prettier:

no-spaced-func

Prettier fixes callback(/* foo */) to callback /* foo */() at which point the rule warns.

no-confusing-arrow with allowParens option

/*eslint no-confusing-arrow: ["error", {"allowParens": true}]*/
/*eslint-env es6*/
var x = a => (1 ? 2 : 3);
var x = (a) => (1 ? 2 : 3);

Prettier removes the brackets which would avoid the error.

react/wrap-multilines

No example here.

no-unexpected-multiline

Prettier transforms

wrapper.find('FilterBy').prop('activeFilters')[1].filters.map(_ => _.key),

to

        wrapper
          .find('FilterBy')
          .prop('activeFilters')
          [1].filters.map(_ => _.key),

At which point the rule warns. But I'd maybe keep it as this can be solved by extracting the stuff into a variable. Wanted to mention it anyways.

Any thoughts on disabling these?

Turn off prefer-arrow-callback by default

👋 Would it be appropriate to add prefer-arrow-callback to the list of conflicting rules to be turned off?

I had issues with this rule conflicting with our eslint config (which extends this prettier config). Turning off prefer-arrow-callback solved our issues.

Can I submit a PR?

List rules that are still enforced

Currently the readme contains a number of rules that are special cases with prettier and mentions that all "styling related lint rules" are disabled by this config.
However as a user of this config I'm interested in what the config is still error-ing on (in other words what kind of bugs/errors will be caught if i use this config?). Would it be possible to add a list of active rules to the readme or another file?

Conflict with @typescript-eslint/eslint-plugin

You probably know about typescript-eslint project. The problem is that Prettier rules are conflicting with those from typescript.

As I understand, this config just disables all rules that possibly conflict with Prettier rules. I'd be happy to open a PR with a fix (disable all conflicting typescript-eslint rules).

Will you consider this solution or you have other ideas regarding this issue?

Prettier 1.4.x breaks linting

I'm not really sure how the plugin works, but if I upgrade to the new prettier, linting fails.
I'm not sure what I need to do to make it work. :/

Basically, it complains that some newlines should not be there anymore:
error Delete ⏎··· prettier/prettier

Even if I run the new version of prettier on my code however, nothing changes, and linting still fails.

This is the report I got from greenkeeper: ZeeCoder/container-query#39 (comment)

Cheers

Add support for typescript-eslint

ESLint recently announced that eslint-plugin-typescript would be moving to typescript-eslint.

When starting a project with the new typescript-eslint and eslint-config-prettier, eslint-config-prettier does not disable styling rules in typescript-eslint. It seems like this because the scopes in typescript.js need to be updated from typescript/ to @typescript-eslint/.

Happy to send a PR over doing that myself if this would suffice!

ESLint config describing prettier's preferences?

In Atom I want to display inline ESLint errors for stuff that will be corrected by prettier-eslint. I expected this config to be a set of ESLint rules describing prettier preferences, not disabling those rules. Am I missing something?

Cannot find module 'eslint-config-prettier/react'

eslint gives me the error: Cannot find module 'eslint-config-prettier/react' with the following config, anything I'm doing wrong?

{
    "extends": [
      "eslint:recommended",
      "plugin:react/recommended",
      "prettier",
      "prettier/react"
    ],
    "parser": "babel-eslint",
    "plugins": [
        "react",
        "prettier"
    ],
    "parserOptions": {
      "ecmaVersion": 2016,
      "sourceType": "module",
      "ecmaFeatures": {
        "jsx": true
      }
    },
    "env": {
      "es6": true,
      "node": true
    },
    "globals": {
        "localStorage": true,
        "ga": true,
        "fetch": true,
        "window": true,
        "document": true,
        "Raven": true,
        "ENV": true
    },
    "rules": {
        "prettier/prettier": ["error", {"trailingComma": true, "singleQuote": true}],
        "no-console": 0,
        "react/sort-comp": [1, {
            "order": [
                "type-annotations",
                "static-methods",
                "lifecycle",
                "everything-else",
                "render"
            ]
        }]
    }
}

eslint --fix runs " Cannot find module 'eslint-config-prettier/vue' " issue

got error on my laravel-vue project

Error:

Error: Cannot find module 'eslint-config-prettier/vue'
Referenced from: C:\xampp\htdocs\numcell-generator\.eslintrc.json
    at ModuleResolver.resolve (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\util\module-resolver.js:72:19)
    at resolve (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config\config-file.js:484:28)
    at load (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config\config-file.js:556:26)
    at configExtends.reduceRight (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config\config-file.js:430:36)
    at Array.reduceRight (<anonymous>)
    at applyExtends (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config\config-file.js:408:26)
    at loadFromDisk (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config\config-file.js:528:22)
    at Object.load (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config\config-file.js:564:20)
    at Config.getLocalConfigHierarchy (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config.js:227:44)
    at Config.getConfigHierarchy (C:\Users\DIKA\AppData\Roaming\npm\node_modules\eslint\lib\config.js:179:43)

.eslintrc.json

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:vue/recommended",
        "plugin:prettier/recommended",
        "prettier",
        "prettier/vue"
    ],
    "parserOptions": {
        "sourceType": "module"
    },
    "plugins": ["vue", "prettier"],
    "rules": {
        "linebreak-style": [
            "error",
            "windows"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "no-console": "off",
        "no-empty": 0,
        "no-unused-vars": 0,
        "no-undef": 0,
        "no-mixed-spaces-and-tabs": 0
    }
}

package.json

{
    "private": true,
    "scripts": {
        "eslint-check": "eslint --print-config . | eslint-config-prettier-check",
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "cross-env": "^5.1",
        "eslint": "^5.13.0",
        "eslint-config-airbnb-base": "^13.1.0",
        "eslint-config-standard": "^12.0.0",
        "eslint-plugin-import": "^2.16.0",
        "eslint-plugin-node": "^8.0.1",
        "eslint-plugin-prettier": "^3.0.1",
        "eslint-plugin-promise": "^4.0.1",
        "eslint-plugin-standard": "^4.0.0",
        "eslint-plugin-vue": "^5.1.0",
        "laravel-mix": "^4.0.14",
        "lodash": "^4.17.5",
        "prettier": "1.16.1",
        "prettier-eslint": "^8.8.2",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.17.0",
        "sass-loader": "^7.1.0",
        "vue": "^2.6.3",
        "vue-template-compiler": "^2.6.3"
    },
    "dependencies": {
        "@vue/eslint-config-prettier": "^4.0.1",
        "ag-grid-community": "^20.0.0",
        "ag-grid-vue": "^20.0.0",
        "moment": "^2.24.0",
        "sweetalert": "^2.1.2",
        "vee-validate": "^2.1.7",
        "vue-infinite-loading": "^2.4.3",
        "vue-multiselect": "^2.1.3",
        "vue-property-decorator": "^7.3.0",
        "vue-router": "^3.0.2",
        "vue-server-renderer": "^2.6.3",
        "vuetify": "^1.5.0",
        "vuex": "^3.1.0"
    },
    "eslintConfig": {
        "root": true,
        "extends": [
            "plugin:vue/essential",
            "plugin:prettier/recommended",
            "eslint:recommended"
        ]
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.