Skip to content

Commit 9048d17

Browse files
author
Kent C. Dodds
authored
fix(eslint): config will not use eslintrc from this project (#4)
There was a problem with the way that eslint fix was applied which basically resulted in test files in this project inheriting from the `eslintConfig` from _this project_ (`prettier-eslint`). So I added `useEslintrc: false` to the config which I believe will fix the issue (can be overridden) Also added a test for the README example so this doesn't happen again!
1 parent c75290c commit 9048d17

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

.all-contributorsrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@
1818
"infra",
1919
"test"
2020
]
21+
},
22+
{
23+
"login": "gyandeeps",
24+
"name": "Gyandeep Singh",
25+
"avatar_url": "https://avatars.githubusercontent.com/u/5554486?v=3",
26+
"profile": "http://gyandeeps.com",
27+
"contributions": [
28+
"review"
29+
]
30+
},
31+
{
32+
"login": "exdeniz",
33+
"name": "Igor Pnev",
34+
"avatar_url": "https://avatars.githubusercontent.com/u/682584?v=3",
35+
"profile": "https://github.com/exdeniz",
36+
"contributions": [
37+
"bug"
38+
]
39+
},
40+
{
41+
"login": "demoneaux",
42+
"name": "Benjamin Tan",
43+
"avatar_url": "https://avatars.githubusercontent.com/u/813865?v=3",
44+
"profile": "https://demoneaux.github.io/",
45+
"contributions": [
46+
"question"
47+
]
2148
}
2249
]
2350
}

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Formats your JavaScript using [`prettier`][prettier] followed by [`eslint --fix`
99
[![downloads][downloads-badge]][npm-stat]
1010
[![MIT License][license-badge]][LICENSE]
1111

12-
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
12+
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)
1313
[![PRs Welcome][prs-badge]][prs]
1414
[![Donate][donate-badge]][donate]
1515
[![Code of Conduct][coc-badge]][coc]
@@ -54,6 +54,9 @@ const sourceCode = 'const {foo} = bar'
5454
const options = {
5555
text: sourceCode,
5656
eslintConfig: {
57+
parserOptions: {
58+
ecmaVersion: 7,
59+
},
5760
rules: {
5861
semi: ['error', 'never'],
5962
},
@@ -118,8 +121,8 @@ None that I'm aware of. Feel free to file a PR if you know of any other solution
118121
Thanks goes to these people ([emoji key][emojis]):
119122

120123
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
121-
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/prettier-eslint/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/prettier-eslint/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/prettier-eslint/commits?author=kentcdodds) |
122-
| :---: |
124+
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/prettier-eslint/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/prettier-eslint/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/prettier-eslint/commits?author=kentcdodds) | [<img src="https://avatars.githubusercontent.com/u/5554486?v=3" width="100px;"/><br /><sub>Gyandeep Singh</sub>](http://gyandeeps.com)<br />👀 | [<img src="https://avatars.githubusercontent.com/u/682584?v=3" width="100px;"/><br /><sub>Igor Pnev</sub>](https://github.com/exdeniz)<br />[🐛](https://github.com/kentcdodds/prettier-eslint/issues?q=author%3Aexdeniz) | [<img src="https://avatars.githubusercontent.com/u/813865?v=3" width="100px;"/><br /><sub>Benjamin Tan</sub>](https://demoneaux.github.io/)<br />💁 |
125+
| :---: | :---: | :---: | :---: |
123126
<!-- ALL-CONTRIBUTORS-LIST:END -->
124127

125128
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!

src/__mocks__/eslint.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function mockGetConfigForFile(filePath) {
3535
return {
3636
'/mock/default-config': {
3737
rules: {
38+
semi: [2, 'never'],
3839
'max-len': [2, 120, 2],
3940
indent: [2, 2, {SwitchCase: 1}],
4041
quotes: [2, 'single', {avoidEscape: true, allowTemplateLiterals: true}],

src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function format({
3535

3636
try {
3737
const pretty = prettify(text, prettierOptions)
38-
return eslintFix(pretty, eslintConfig)
38+
const eslintFixed = eslintFix(pretty, eslintConfig)
39+
return eslintFixed
3940
} finally {
4041
options.disableLog = originalLogValue
4142
}
@@ -53,7 +54,13 @@ function prettify(text, formatOptions) {
5354

5455
function eslintFix(text, eslintConfig) {
5556
const eslintOptions = {
57+
// overrideables
58+
useEslintrc: false,
59+
60+
// user-given config
5661
...eslintConfig,
62+
63+
// overrides
5764
fix: true,
5865
// there's some trouble with `globals`...
5966
// I'm pretty sure it's not necessary to have them

src/index.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ const tests = [
1515
},
1616
output: defaultOutput(),
1717
},
18+
{
19+
title: 'README example',
20+
input: {
21+
text: 'const {foo} = bar',
22+
eslintConfig: {
23+
parserOptions: {
24+
ecmaVersion: 7,
25+
},
26+
rules: {
27+
semi: ['error', 'never'],
28+
},
29+
},
30+
prettierOptions: {
31+
bracketSpacing: true,
32+
},
33+
},
34+
output: 'const { foo } = bar',
35+
},
1836
{
1937
title: 'with a filePath and no config',
2038
input: {
@@ -110,7 +128,11 @@ test('can disable log on a single call as part of the options', () => {
110128

111129
function getESLintConfigWithDefaultRules(overrides) {
112130
return {
131+
parserOptions: {
132+
ecmaVersion: 7,
133+
},
113134
rules: {
135+
semi: [2, 'never'],
114136
'max-len': [2, 120, 2],
115137
indent: [2, 2, {SwitchCase: 1}],
116138
quotes: [2, 'single', {avoidEscape: true, allowTemplateLiterals: true}],

0 commit comments

Comments
 (0)