Skip to content

Commit

Permalink
feat!: upgrade eslint v8 (fixes #61)
Browse files Browse the repository at this point in the history
the main change is to replace eslint.CliEngine to eslint.ESLint, as CLIEngine
has been removed.

refs: https://eslint.org/docs/8.0.0/user-guide/migrating-to-8.0.0#remove-cliengine

fix: rm no needed deps

these eslint plugins has been installed as eslint-config-react-app's deps.
  • Loading branch information
aladdin-add committed Nov 23, 2021
1 parent b58b110 commit b82bb60
Show file tree
Hide file tree
Showing 5 changed files with 917 additions and 1,425 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -24,6 +24,7 @@ Despite all the recent hype, setting up a new TypeScript (x React) library can b
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Features](#features)
- [Quick Start](#quick-start)
- [`npm start` or `yarn start`](#npm-start-or-yarn-start)
Expand Down
16 changes: 3 additions & 13 deletions package.json
Expand Up @@ -55,13 +55,9 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-replace": "^3.0.0",
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@types/jest": "^27.0.2",
"ansi-escapes": "^4.3.2",
"asyncro": "^3.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.3.1",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-dev-expression": "^0.2.3",
"babel-plugin-macros": "^3.1.0",
Expand All @@ -70,15 +66,9 @@
"camelcase": "^6.2.1",
"chalk": "^4.1.2",
"enquirer": "^2.3.6",
"eslint": "^7.32.0",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.10.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-config-react-app": "^7.0.0-next.91",
"execa": "^4.1.0",
"figlet": "^1.5.2",
"fs-extra": "^10.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/createEslintConfig.ts
@@ -1,6 +1,6 @@
import fs from 'fs-extra';
import path from 'path';
import { CLIEngine } from 'eslint';
import { Linter } from 'eslint';
import { PackageJson } from './types';
import { getReactVersion } from './utils';

Expand All @@ -13,7 +13,7 @@ export async function createEslintConfig({
pkg,
rootDir,
writeFile,
}: CreateEslintConfigArgs): Promise<CLIEngine.Options['baseConfig'] | void> {
}: CreateEslintConfigArgs): Promise<Linter.Config | void> {
const isReactLibrary = Boolean(getReactVersion(pkg));

const config = {
Expand Down
75 changes: 44 additions & 31 deletions src/index.ts
Expand Up @@ -15,7 +15,7 @@ import chalk from 'chalk';
import figlet from 'figlet';
import * as fs from 'fs-extra';
import * as jest from 'jest';
import { CLIEngine } from 'eslint';
import { ESLint } from 'eslint';
import logError from './logError';
import path from 'path';
import execa from 'execa';
Expand Down Expand Up @@ -574,38 +574,51 @@ prog
)
);
}
try {
const config = await createEslintConfig({
pkg: appPackageJson,
rootDir: paths.appRoot,
writeFile: opts['write-file'],
});

const config = await createEslintConfig({
pkg: appPackageJson,
rootDir: paths.appRoot,
writeFile: opts['write-file'],
});
const linter = new ESLint({
baseConfig: {
...config,
...appPackageJson.eslint,
ignorePatterns: opts['ignore-pattern'],
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
fix: opts.fix,
});
const results = await linter.lintFiles(opts['_']);
if (opts.fix) {
await ESLint.outputFixes(results);
}

const cli = new CLIEngine({
baseConfig: {
...config,
...appPackageJson.eslint,
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
fix: opts.fix,
ignorePattern: opts['ignore-pattern'],
});
const report = cli.executeOnFiles(opts['_']);
if (opts.fix) {
CLIEngine.outputFixes(report);
}
console.log(cli.getFormatter()(report.results));
if (opts['report-file']) {
await fs.outputFile(
opts['report-file'],
cli.getFormatter('json')(report.results)
);
}
if (report.errorCount) {
process.exit(1);
}
if (report.warningCount > opts['max-warnings']) {
process.exit(1);
const formatter = await linter.loadFormatter('stylish');
const jsonFormatter = await linter.loadFormatter('json');
console.log(formatter.format(results));
if (opts['report-file']) {
await fs.outputFile(
opts['report-file'],
jsonFormatter.format(results)
);
}
let errorCount = 0;
let warningCount = 0;
results.forEach((result) => {
errorCount += result.errorCount;
warningCount += result.warningCount;
});
if (errorCount > 0) {
process.exit(1);
}
if (warningCount > opts['max-warnings']) {
process.exit(1);
}
} catch (e) {
process.exitCode = 1;
console.error(e);
}
}
);
Expand Down

0 comments on commit b82bb60

Please sign in to comment.