Skip to content

Commit

Permalink
Support ESLint v7 (#272)
Browse files Browse the repository at this point in the history
* deps: update ESLint v7

BREAKING CHANGE: Support minimum ESLint version is v7.

* test: use ESLint class instead of CLIEngine

* deps: update typescript-eslint version to v3

* deps: update eslint-plugin-flowtype version to v5

* deps: update eslint plugins for react

BREAKING CHANGE: eslint-plugin-react-hooks reports new errors

* fix: review newly added rules in typescript-eslint

BREAKING CHANGE: enable new rules in typescript-eslint/recommended

* deps: update all plugin versions to laest

* test: fix failed tests

* test: fix failed tests

* deps: update eslint-plugin-jsx-a11y to v6.3.0
  • Loading branch information
koba04 committed Jun 19, 2020
1 parent 74276ec commit 398512d
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 243 deletions.
13 changes: 3 additions & 10 deletions lib/typescript.js
@@ -1,10 +1,7 @@
module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
extends: ["plugin:@typescript-eslint/recommended"],
// It's 5〜10x slower with the project setting.
// So We disable it until the issue has been fixed
/*
Expand All @@ -17,15 +14,12 @@ module.exports = {

"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/type-annotation-spacing": "warn",
"@typescript-eslint/unified-signatures": "warn",
"@typescript-eslint/indent": ["warn", 2, { SwitchCase: 1 }],

"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-inferrable-types": "off",
Expand All @@ -34,7 +28,6 @@ module.exports = {
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-triple-slash-reference": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-interface": "off",
"@typescript-eslint/prefer-namespace-keyword": "off"
Expand Down
472 changes: 336 additions & 136 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Expand Up @@ -28,7 +28,7 @@
"license": "MIT",
"devDependencies": {
"@types/react": "^16.9.38",
"eslint": "^6.8.0",
"eslint": "^7.2.0",
"mocha": "^7.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
Expand All @@ -37,20 +37,20 @@
"typescript": "^3.9.5"
},
"peerDependencies": {
"eslint": "^6.4.0",
"eslint": "^7.0.0",
"typescript": "^3.3.3333"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@typescript-eslint/eslint-plugin": "^3.2.0",
"@typescript-eslint/parser": "^3.2.0",
"babel-eslint": "^10.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-flowtype": "^5.1.3",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jsx-a11y": "^6.3.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.1"
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^4.0.4"
}
}
6 changes: 2 additions & 4 deletions test/base-test.js
Expand Up @@ -2,15 +2,13 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("base", () => {
it("should get expected errors and warninigs with base config", () => {
const result = runLintWithFixtures("base");
it("should get expected errors and warninigs with base config", async () => {
const result = await runLintWithFixtures("base");
assert.deepStrictEqual(result, {
"error.js": {
errors: [
"no-var",
"no-unused-vars",
"no-var",
"no-redeclare",
"getter-return",
"no-self-assign",
"no-import-assign",
Expand Down
6 changes: 3 additions & 3 deletions test/es5-test.js
Expand Up @@ -2,11 +2,11 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("es5", () => {
it("should get expected errors and warninigs with es5 config", () => {
const result = runLintWithFixtures("es5");
it("should get expected errors and warninigs with es5 config", async () => {
const result = await runLintWithFixtures("es5");
assert.deepStrictEqual(result, {
"error.js": {
errors: ["no-unused-vars", "no-redeclare"]
errors: ["no-unused-vars"]
},
"warning.js": {
warnings: ["array-callback-return"]
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/base/error.js
@@ -1,6 +1,5 @@
import mod from './mod';

var foo = {};
var foo = {};
const obj = {
a: 'a',
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/es5/error.js
@@ -1,3 +1,2 @@
var obj = {};
var obj = {};

4 changes: 2 additions & 2 deletions test/flowtype-test.js
Expand Up @@ -2,9 +2,9 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("flowtype", () => {
it("should get expected errors and warninigs with react config with flowtype config", () => {
it("should get expected errors and warninigs with react config with flowtype config", async () => {
// We use react presets in order to support ES2017 syntax
const result = runLintWithFixtures("flowtype");
const result = await runLintWithFixtures("flowtype");
assert.deepStrictEqual(result, {
"ok.js": {},
"error.js": {
Expand Down
7 changes: 5 additions & 2 deletions test/globals-kintone-test.js
Expand Up @@ -2,8 +2,11 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("kintone", () => {
it("should get expected errors and warninigs with kintone config", () => {
const result = runLintWithFixtures("globals-kintone", "globals/kintone.js");
it("should get expected errors and warninigs with kintone config", async () => {
const result = await runLintWithFixtures(
"globals-kintone",
"globals/kintone.js"
);
assert.deepStrictEqual(result, {
"error.js": {
errors: ["no-undef"]
Expand Down
4 changes: 2 additions & 2 deletions test/kintone-test.js
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("kintone", () => {
it("should get expected errors and warninigs with kintone config", () => {
const result = runLintWithFixtures("kintone");
it("should get expected errors and warninigs with kintone config", async () => {
const result = await runLintWithFixtures("kintone");
assert.deepStrictEqual(result, {
"error.js": {
errors: ["strict", "strict"]
Expand Down
12 changes: 6 additions & 6 deletions test/lib/runLintWithFixtures.js
@@ -1,24 +1,24 @@
"use strict";

const CLIEngine = require("eslint").CLIEngine;
const { ESLint } = require("eslint");
const path = require("path");

/**
* Run ESlint and return the result per files
* @param type lint type, which is in lib directory
* @returns {Object} lint results {[fileName]: {errors: [ruleNames], warnings: [ruleNames]}}
*/
const runLintWithFixtures = (type, configFile = `lib/${type}.js`) => {
const cli = new CLIEngine({
configFile: path.resolve(process.cwd(), configFile),
const runLintWithFixtures = async (type, configFile = `lib/${type}.js`) => {
const eslint = new ESLint({
overrideConfigFile: path.resolve(process.cwd(), configFile),
ignore: false,
useEslintrc: false,
extensions: [".js", ".jsx", ".ts", ".tsx"]
});
const targetDir = path.resolve(__dirname, "..", "fixtures", type);
const lintResult = cli.executeOnFiles([targetDir]);
const lintResult = await eslint.lintFiles([targetDir]);
// console.log(JSON.stringify(lintResult, null, 2));
return lintResult.results.reduce((results, { filePath, messages }) => {
return lintResult.reduce((results, { filePath, messages }) => {
// strip path
const fileName = filePath.replace(`${targetDir}/`, "");
return Object.assign(results, {
Expand Down
4 changes: 2 additions & 2 deletions test/node-test.js
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("node", () => {
it("should get expected errors and warninigs with node config", () => {
const result = runLintWithFixtures("node");
it("should get expected errors and warninigs with node config", async () => {
const result = await runLintWithFixtures("node");
assert.deepStrictEqual(result, {
"error.js": {
errors: [
Expand Down
4 changes: 2 additions & 2 deletions test/node-typescript.js
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("node-typescript", () => {
it("should get expected errors and warninigs", () => {
const result = runLintWithFixtures(
it("should get expected errors and warninigs", async () => {
const result = await runLintWithFixtures(
"node-typescript",
"presets/node-typescript-prettier.js"
);
Expand Down

0 comments on commit 398512d

Please sign in to comment.