最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get ESLint --fix to also run prettier --write - Stack Overflow

programmeradmin3浏览0评论

It is possible to configure your .eslintrc so that running eslint --fix would run also run prettier --write as well?

Right now I need to do prettier --write && eslint --fix and I was hoping I could just run the one mand.

Update

Using prettier-eslint "works" except it does not apply my custom overrides:

My .eslintrc.js looks like

module.exports = { 
  extends: [
    'prettier',
  ],
  plugins: [
    'prettier',
  ],
  rules: {
    'prettier/prettier': [
      'error',
      {
        'singleQuote': true,
      },
    ],
  }
};

Then I have a dummy file.js:

const path = require("path");
const foo = () => {
    return path;
}

If I run eslint ./file.js I get expected output:

error Replace "path" with 'path' prettier/prettier

But when I run prettier-eslint --eslint-config-path .eslintrc.js --write ./file.js it keeps the " and does not replace it with '

I do not want to have a separate file for prettierrc and want to keep both in one file.

It is possible to configure your .eslintrc so that running eslint --fix would run also run prettier --write as well?

Right now I need to do prettier --write && eslint --fix and I was hoping I could just run the one mand.

Update

Using prettier-eslint "works" except it does not apply my custom overrides:

My .eslintrc.js looks like

module.exports = { 
  extends: [
    'prettier',
  ],
  plugins: [
    'prettier',
  ],
  rules: {
    'prettier/prettier': [
      'error',
      {
        'singleQuote': true,
      },
    ],
  }
};

Then I have a dummy file.js:

const path = require("path");
const foo = () => {
    return path;
}

If I run eslint ./file.js I get expected output:

error Replace "path" with 'path' prettier/prettier

But when I run prettier-eslint --eslint-config-path .eslintrc.js --write ./file.js it keeps the " and does not replace it with '

I do not want to have a separate file for prettierrc and want to keep both in one file.

Share Improve this question edited Oct 31, 2019 at 19:53 Kousha asked Oct 31, 2019 at 17:56 KoushaKousha 36.4k59 gold badges188 silver badges314 bronze badges 1
  • If you're doing this on git hooks. you can simply use husky – Code Maniac Commented Oct 31, 2019 at 18:02
Add a ment  | 

1 Answer 1

Reset to default 3

There's a great package called prettier-eslint that we've used at work before. It will format using prettier and then run eslint --fix on your code. We liked it, give it a try!

发布评论

评论列表(0)

  1. 暂无评论