Skip to content

Commit 4e4077d

Browse files
authored
feat: 📦 Support ESLint 8 (#431)
BREAKING CHANGE: Requires ESLint 8. ESLint 8 API changes caused the format function to now be asynchronous. Requires minimum Node 12 as required by ESLint 8
1 parent afc22f5 commit 4e4077d

12 files changed

+96
-57
lines changed

Diff for: .all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@
231231
"code",
232232
"maintenance"
233233
]
234+
},
235+
{
236+
"login": "idahogurl",
237+
"name": "Rebecca Vest",
238+
"avatar_url": "https://avatars.githubusercontent.com/u/10620169?v=4",
239+
"profile": "https://campcode.dev/",
240+
"contributions": [
241+
"code"
242+
]
234243
}
235244
],
236245
"repoType": "github",

Diff for: .eslintrc.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
const config = {
2-
extends: ["kentcdodds", "kentcdodds/jest"],
2+
extends: ['kentcdodds', 'kentcdodds/jest'],
33
rules: {
4-
"max-len": "off",
5-
"import/max-dependencies": "off",
6-
"space-before-function-paren": [
7-
"error",
4+
quotes: ['error', 'single', { avoidEscape: true }],
5+
'arrow-parens': ['error', 'as-needed'],
6+
'max-len': 'off',
7+
'import/max-dependencies': 'off',
8+
'space-before-function-paren': [
9+
'error',
810
{
9-
anonymous: "never",
10-
named: "never",
11-
asyncArrow: "always"
11+
anonymous: 'never',
12+
named: 'never',
13+
asyncArrow: 'always'
1214
}
1315
]
1416
}

Diff for: README.md

+25-24
Large diffs are not rendered by default.

Diff for: __mocks__/glob.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = jest.fn(function mockGlob(globString, options, callback) {
6363
} else {
6464
throw new Error(
6565
`Your test globString: "${globString}"` +
66-
` doesn't have associated mock data.`
66+
" doesn't have associated mock data."
6767
);
6868
}
6969
});

Diff for: __mocks__/prettier-eslint.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const format = jest.fn(({ text, filePath = '' }) => {
1111
} else if (filePath.includes('eslint-config-error')) {
1212
throw new Error('Some weird eslint config error');
1313
} else if (filePath.includes('no-change')) {
14-
return text;
14+
return Promise.resolve(text);
1515
}
16-
return `MOCK_OUTPUT for ${filePath || 'stdin'}`;
16+
return Promise.resolve(`MOCK_OUTPUT for ${filePath || 'stdin'}`);
1717
});
1818

1919
export default format;

Diff for: babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const config = {
44
'@babel/preset-env',
55
{
66
targets: {
7-
node: '8'
7+
node: '12'
88
},
99
useBuiltIns: 'usage',
1010
corejs: 3

Diff for: cli-test/override-config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
quotes: ['error', 'double']
4+
}
5+
};

Diff for: cli-test/tests/index.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ test('formats files and outputs to stdout', async () => {
7171
);
7272
});
7373

74+
test('handles --eslint-config-path', async () => {
75+
// can't just do the testOutput function here because
76+
// the output is in an undeterministic order
77+
const stdout = await runPrettierESLintCLI(
78+
`cli-test/fixtures/stdout1.js --no-eslint-ignore --no-prettier-ignore --eslint-config-path ${__dirname}/../override-config.js`
79+
);
80+
expect(stdout).toContain(
81+
stripIndent(
82+
`
83+
import baz, { stuff } from "fdjakfdlfw-baz";
84+
85+
export { bazzy };
86+
87+
function bazzy(something) {
88+
return baz(stuff(something));
89+
}
90+
`
91+
).trim()
92+
);
93+
});
94+
7495
test('list different files with the --list-different option', async () => {
7596
// can't just do the testOutput function here because
7697
// the output is in an undeterministic order
@@ -96,8 +117,8 @@ test(`prettier-eslint ${writeCommand}`, async () => {
96117
const example1Path = path.resolve(__dirname, '../fixtures/example1.js');
97118
const example2Path = path.resolve(__dirname, '../fixtures/example2.js');
98119
try {
99-
const example1 = `const { example1 } = baz.bar`;
100-
const example2 = `function example2(thing){return thing;};;;;;;;;;`;
120+
const example1 = 'const { example1 } = baz.bar';
121+
const example2 = 'function example2(thing){return thing;};;;;;;;;;';
101122
await Promise.all([
102123
pWriteFile(example1Path, example1),
103124
pWriteFile(example2Path, example2)

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "CLI for prettier-eslint",
55
"main": "dist/no-main.js",
66
"engines": {
7-
"node": ">=8"
7+
"node": ">=12.22"
88
},
99
"bin": {
1010
"prettier-eslint": "dist/index.js"
@@ -30,7 +30,7 @@
3030
"chalk": "^2.4.2",
3131
"common-tags": "^1.8.0",
3232
"core-js": "^3.1.4",
33-
"eslint": "^5.0.0",
33+
"eslint": "^8.14.0",
3434
"find-up": "^4.1.0",
3535
"get-stdin": "^7.0.0",
3636
"glob": "^7.1.4",
@@ -39,7 +39,7 @@
3939
"lodash.memoize": "^4.1.2",
4040
"loglevel-colored-level-prefix": "^1.0.0",
4141
"messageformat": "^2.2.1",
42-
"prettier-eslint": "^9.0.0",
42+
"prettier-eslint": "^14.0.3",
4343
"rxjs": "^6.5.2",
4444
"yargs": "^13.2.4"
4545
},
@@ -53,7 +53,7 @@
5353
"ajv": "^6.10.0",
5454
"all-contributors-cli": "^6.7.0",
5555
"babel-jest": "^24.8.0",
56-
"eslint-config-kentcdodds": "14.3.3",
56+
"eslint-config-kentcdodds": "^20.2.0",
5757
"husky": "^2.4.1",
5858
"jest": "^24.8.0",
5959
"jest-cli": "^24.8.0",

Diff for: src/format-files.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import findUp from 'find-up';
1313
import memoize from 'lodash.memoize';
1414
import indentString from 'indent-string';
1515
import getLogger from 'loglevel-colored-level-prefix';
16-
import ConfigFile from 'eslint/lib/config/config-file';
17-
import Linter from 'eslint/lib/linter';
18-
import Config from 'eslint/lib/config';
1916
import * as messages from './messages';
2017

2118
const LINE_SEPERATOR_REGEX = /(\r|\n|\r\n)/;
@@ -69,11 +66,9 @@ function formatFilesFromArgv({
6966
};
7067

7168
if (eslintConfigPath) {
72-
const configContext = new Config({}, new Linter());
73-
prettierESLintOptions.eslintConfig = ConfigFile.load(
74-
eslintConfigPath,
75-
configContext
76-
);
69+
prettierESLintOptions.eslintConfig = {
70+
overrideConfigFile: eslintConfigPath
71+
};
7772
}
7873

7974
const cliOptions = { write, listDifferent };
@@ -94,7 +89,10 @@ function formatFilesFromArgv({
9489
async function formatStdin(prettierESLintOptions) {
9590
const stdinValue = (await getStdin()).trim();
9691
try {
97-
const formatted = format({ text: stdinValue, ...prettierESLintOptions });
92+
const formatted = await format({
93+
text: stdinValue,
94+
...prettierESLintOptions
95+
});
9896
process.stdout.write(formatted);
9997
return Promise.resolve(formatted);
10098
} catch (error) {
@@ -238,9 +236,13 @@ function getFilesFromGlob(
238236
function formatFile(filePath, prettierESLintOptions, cliOptions) {
239237
const fileInfo = { filePath };
240238
let format$ = rxReadFile(filePath, 'utf8').pipe(
241-
map(text => {
239+
mergeMap(async text => {
242240
fileInfo.text = text;
243-
fileInfo.formatted = format({ text, filePath, ...prettierESLintOptions });
241+
fileInfo.formatted = await format({
242+
text,
243+
filePath,
244+
...prettierESLintOptions
245+
});
244246
fileInfo.unchanged = fileInfo.text === fileInfo.formatted;
245247
return fileInfo;
246248
})

Diff for: src/messages.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ const mf = new MessageFormat('en');
55
export { success, failure, unchanged };
66

77
function success(data) {
8-
const files = `{count, plural, one{file} other{files}}`;
8+
const files = '{count, plural, one{file} other{files}}';
99
return mf.compile(
1010
`{success} formatting {countString} ${files} with prettier-eslint`
1111
)(data);
1212
}
1313

1414
function failure(data) {
15-
const files = `{count, plural, one{file} other{files}}`;
15+
const files = '{count, plural, one{file} other{files}}';
1616
return mf.compile(
1717
`{failure} formatting {countString} ${files} with prettier-eslint`
1818
)(data);
1919
}
2020

2121
function unchanged(data) {
22-
const files = `{count, plural, one{file was} other{files were}}`;
22+
const files = '{count, plural, one{file was} other{files were}}';
2323
return mf.compile(`{countString} ${files} {unchanged}`)(data);
2424
}

Diff for: src/parser.js

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ const parser = yargs
133133
},
134134
'jsx-bracket-same-line': {
135135
type: 'boolean',
136-
default: undefined,
137136
describe: oneLine`
138137
Put the > of a multi-line JSX element at
139138
the end of the last line instead of

0 commit comments

Comments
 (0)