From 06682c969db2afa2b7e6507bfb099809c59cc689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 9 Feb 2020 23:17:22 -0500 Subject: [PATCH 1/3] chore: add eslint-plugin-jest --- .eslintrc.js | 10 +++++++++- package.json | 1 + yarn.lock | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 943c853d421a..6eea9bc6f6fc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,7 @@ const path = require("path"); module.exports = { root: true, - plugins: ["prettier", "@babel/development", "import"], + plugins: ["prettier", "@babel/development", "import", "jest"], // replace it by `@babel/internal` when `@babel/eslint-config-internal` is published extends: path.resolve(__dirname, "eslint/babel-eslint-config-internal"), rules: { @@ -38,6 +38,14 @@ module.exports = { env: { jest: true, }, + extends: "plugin:jest/recommended", + rules: { + "jest/expect-expect": "off", + "jest/no-identical-title": "off", + "jest/no-standalone-expect": "off", + "jest/no-test-callback": "off", + "jest/valid-describe": "off" + } }, { files: ["packages/babel-plugin-*/src/index.js"], diff --git a/package.json b/package.json index 4aac94157afa..2fcd352ec8fd 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "eslint-import-resolver-node": "^0.3.2", "eslint-plugin-flowtype": "^3.8.2", "eslint-plugin-import": "^2.17.2", + "eslint-plugin-jest": "^23.7.0", "eslint-plugin-prettier": "^3.1.0", "fancy-log": "^1.3.3", "flow-bin": "^0.108.0", diff --git a/yarn.lock b/yarn.lock index 9e8330196f57..e5ab59bb258b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1910,6 +1910,11 @@ "@types/istanbul-lib-coverage" "*" "@types/istanbul-lib-report" "*" +"@types/json-schema@^7.0.3": + version "7.0.4" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" + integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -1949,6 +1954,28 @@ dependencies: "@types/yargs-parser" "*" +"@typescript-eslint/experimental-utils@^2.5.0": + version "2.19.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.19.0.tgz#d5ca732f22c009e515ba09fcceb5f2127d841568" + integrity sha512-zwpg6zEOPbhB3+GaQfufzlMUOO6GXCNZq6skk+b2ZkZAIoBhVoanWK255BS1g5x9bMwHpLhX0Rpn5Fc3NdCZdg== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.19.0" + eslint-scope "^5.0.0" + +"@typescript-eslint/typescript-estree@2.19.0": + version "2.19.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.19.0.tgz#6bd7310b9827e04756fe712909f26956aac4b196" + integrity sha512-n6/Xa37k0jQdwpUszffi19AlNbVCR0sdvCs3DmSKMD7wBttKY31lhD2fug5kMD91B2qW4mQldaTEc1PEzvGu8w== + dependencies: + debug "^4.1.1" + eslint-visitor-keys "^1.1.0" + glob "^7.1.6" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^6.3.0" + tsutils "^3.17.1" + "@zkochan/cmd-shim@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@zkochan/cmd-shim/-/cmd-shim-3.1.0.tgz#2ab8ed81f5bb5452a85f25758eb9b8681982fd2e" @@ -4229,6 +4256,13 @@ eslint-plugin-import@^2.17.2: read-pkg-up "^2.0.0" resolve "^1.12.0" +eslint-plugin-jest@^23.7.0: + version "23.7.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.7.0.tgz#84d5603b6e745b59898cb6750df6a44782a39b04" + integrity sha512-zkiyGlvJeHNjAEz8FaIxTXNblJJ/zj3waNbYbgflK7K6uy0cpE5zJBt/JpJtOBGM/UGkC6BqsQ4n0y7kQ2HA8w== + dependencies: + "@typescript-eslint/experimental-utils" "^2.5.0" + eslint-plugin-prettier@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.1.tgz#507b8562410d02a03f0ddc949c616f877852f2ba" @@ -5133,7 +5167,7 @@ glob-watcher@^5.0.3: just-debounce "^1.0.0" object.defaults "^1.1.0" -glob@^7.0.0, glob@^7.0.3, glob@^7.1.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4: +glob@^7.0.0, glob@^7.0.3, glob@^7.1.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: version "7.1.6" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -10378,11 +10412,18 @@ trim-off-newlines@^1.0.0: resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= -tslib@^1.9.0: +tslib@^1.8.1, tslib@^1.9.0: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== +tsutils@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" + integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + dependencies: + tslib "^1.8.1" + tty-browserify@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811" From 2b6715a313c825f396dd3af48895a8f8523e3d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 9 Feb 2020 23:32:47 -0500 Subject: [PATCH 2/3] chore: update test sources --- eslint/babel-eslint-parser/test/index.js | 2 ++ .../test/integration/eslint/eslint.js | 6 ++++-- packages/babel-core/test/option-manager.js | 8 ++++---- .../babel-plugin-syntax-decorators/test/index.js | 2 +- packages/babel-template/test/index.js | 10 ++++------ .../babel-traverse/test/__snapshots__/scope.js.snap | 12 ++++++++++++ packages/babel-traverse/test/scope.js | 8 ++++++-- packages/babel-traverse/test/traverse.js | 3 ++- 8 files changed, 35 insertions(+), 16 deletions(-) diff --git a/eslint/babel-eslint-parser/test/index.js b/eslint/babel-eslint-parser/test/index.js index 3e692340ce59..a5158b4aa640 100644 --- a/eslint/babel-eslint-parser/test/index.js +++ b/eslint/babel-eslint-parser/test/index.js @@ -283,10 +283,12 @@ describe("babylon-to-espree", () => { assert.strictEqual(babylonAST.tokens[3].value, "#"); }); + // eslint-disable-next-line jest/no-disabled-tests it.skip("empty program with line comment", () => { parseAndAssertSame("// single comment"); }); + // eslint-disable-next-line jest/no-disabled-tests it.skip("empty program with block comment", () => { parseAndAssertSame(" /* multiline\n * comment\n*/"); }); diff --git a/eslint/babel-eslint-tests/test/integration/eslint/eslint.js b/eslint/babel-eslint-tests/test/integration/eslint/eslint.js index 4d7160720030..1a62e20f56a9 100644 --- a/eslint/babel-eslint-tests/test/integration/eslint/eslint.js +++ b/eslint/babel-eslint-tests/test/integration/eslint/eslint.js @@ -1252,6 +1252,7 @@ describe("verify", () => { // This two tests are disabled, as the feature to visit properties when // there is a spread/rest operator has been removed as it caused problems // with other rules #249 + // eslint-disable-next-line jest/no-disabled-tests it.skip("visits excluded properties left of spread #95", () => { verifyAndAssertMessages( "var originalObject = {}; var {field1, field2, ...clone} = originalObject;", @@ -1259,6 +1260,7 @@ describe("verify", () => { ); }); + // eslint-disable-next-line jest/no-disabled-tests it.skip("visits excluded properties left of spread #210", () => { verifyAndAssertMessages( "const props = { yo: 'yo' }; const { ...otherProps } = props;", @@ -1569,9 +1571,9 @@ describe("verify", () => { verifyAndAssertMessages("with (arguments) { length; }", {}, [], "script"); }); - xit("with does crash parsing in module mode (strict on) #171", () => { + it("with does crash parsing in module mode (strict on) #171", () => { verifyAndAssertMessages("with (arguments) { length; }", {}, [ - "1:1 Parsing error: 'with' in strict mode", + /'with' in strict mode/, ]); }); diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js index 880d80f411d7..e792d27f0500 100644 --- a/packages/babel-core/test/option-manager.js +++ b/packages/babel-core/test/option-manager.js @@ -94,8 +94,8 @@ describe("option-manager", () => { expect(() => { loadOptions({ plugins: [[plugin, null]], - }).toThrow(/.plugins[0][1] must be an object, false, or undefined/); - }); + }); + }).toThrow(".plugins[0][1] must be an object, false, or undefined"); expect(calls).toEqual([]); }); @@ -140,8 +140,8 @@ describe("option-manager", () => { expect(() => { loadOptions({ presets: [preset, preset], - }).toThrow(/Duplicate plugin\/preset detected/); - }); + }); + }).toThrow(/Duplicate plugin\/preset detected/); expect(calls).toEqual([]); }); diff --git a/packages/babel-plugin-syntax-decorators/test/index.js b/packages/babel-plugin-syntax-decorators/test/index.js index d84797d7bbf8..bd5ff21888f3 100644 --- a/packages/babel-plugin-syntax-decorators/test/index.js +++ b/packages/babel-plugin-syntax-decorators/test/index.js @@ -33,7 +33,7 @@ describe("'decoratorsBeforeExport' option", function() { expect(makeParser("", { decoratorsBeforeExport: "before" })).toThrow(); }); - test.skip("is required", function() { + test("is required", function() { expect(makeParser("", { legacy: false })).toThrow(/decoratorsBeforeExport/); }); diff --git a/packages/babel-template/test/index.js b/packages/babel-template/test/index.js index a90db40540e4..ebac1d142d7e 100644 --- a/packages/babel-template/test/index.js +++ b/packages/babel-template/test/index.js @@ -219,7 +219,7 @@ describe("@babel/template", function() { }); }); - describe.only(".syntacticPlaceholders", () => { + describe(".syntacticPlaceholders", () => { it("works in function body", () => { const output = template(`function f() %%A%%`)({ A: t.blockStatement([]), @@ -302,12 +302,10 @@ describe("@babel/template", function() { }); it("replaces identifiers", () => { - expect(() => { - const output = template(`FOO`)({ - FOO: t.numericLiteral(1), - }); - expect(generator(output).code).toMatchInlineSnapshot(`"1;"`); + const output = template(`FOO`)({ + FOO: t.numericLiteral(1), }); + expect(generator(output).code).toMatchInlineSnapshot(`"1;"`); }); it("doesn't mix placeholder styles", () => { diff --git a/packages/babel-traverse/test/__snapshots__/scope.js.snap b/packages/babel-traverse/test/__snapshots__/scope.js.snap index 631ca61d5af7..a7b6a4d195df 100644 --- a/packages/babel-traverse/test/__snapshots__/scope.js.snap +++ b/packages/babel-traverse/test/__snapshots__/scope.js.snap @@ -4,8 +4,12 @@ exports[`scope duplicate bindings catch const 1`] = `"Duplicate declaration \\"e exports[`scope duplicate bindings catch let 1`] = `"Duplicate declaration \\"e\\""`; +exports[`scope duplicate bindings global class/const 1`] = `"Duplicate declaration \\"foo\\""`; + exports[`scope duplicate bindings global class/function 1`] = `"Duplicate declaration \\"foo\\""`; +exports[`scope duplicate bindings global class/let 1`] = `"Duplicate declaration \\"foo\\""`; + exports[`scope duplicate bindings global const/class 1`] = `"Duplicate declaration \\"foo\\""`; exports[`scope duplicate bindings global const/const 1`] = `"Duplicate declaration \\"foo\\""`; @@ -16,10 +20,18 @@ exports[`scope duplicate bindings global const/let 1`] = `"Duplicate declaration exports[`scope duplicate bindings global const/var 1`] = `"Duplicate declaration \\"foo\\""`; +exports[`scope duplicate bindings global function/class 1`] = `"Duplicate declaration \\"foo\\""`; + +exports[`scope duplicate bindings global function/let 1`] = `"Duplicate declaration \\"foo\\""`; + exports[`scope duplicate bindings global let/class 1`] = `"Duplicate declaration \\"foo\\""`; +exports[`scope duplicate bindings global let/const 1`] = `"Duplicate declaration \\"foo\\""`; + exports[`scope duplicate bindings global let/function 1`] = `"Duplicate declaration \\"foo\\""`; exports[`scope duplicate bindings global let/let 1`] = `"Duplicate declaration \\"foo\\""`; exports[`scope duplicate bindings global let/var 1`] = `"Duplicate declaration \\"foo\\""`; + +exports[`scope duplicate bindings global var/let 1`] = `"Duplicate declaration \\"foo\\""`; diff --git a/packages/babel-traverse/test/scope.js b/packages/babel-traverse/test/scope.js index d4115b1c9e86..26efc491409e 100644 --- a/packages/babel-traverse/test/scope.js +++ b/packages/babel-traverse/test/scope.js @@ -422,7 +422,11 @@ describe("scope", () => { } }); - /*if (kind1 !== kind2) { + if (kind1 !== kind2) { + //todo: remove the if whitelist + if (kind1 === "const" && (kind2 === "function" || kind2 === "var")) { + continue; + } it(`${kind2}/${kind1}`, () => { const ast = createAST(kind2, kind1); @@ -432,7 +436,7 @@ describe("scope", () => { expect(() => getPath(ast)).toThrowErrorMatchingSnapshot(); } }); - }*/ + } } }); }); diff --git a/packages/babel-traverse/test/traverse.js b/packages/babel-traverse/test/traverse.js index 316c2e12c0d8..3d21529cea1c 100644 --- a/packages/babel-traverse/test/traverse.js +++ b/packages/babel-traverse/test/traverse.js @@ -196,7 +196,8 @@ describe("traverse", function() { expect(skipped).toBe(true); }); - // Skipped: see the comment in the `NodePath.requque` method. + // Skipped: see the comment in the `NodePath.requeue` method. + // eslint-disable-next-line jest/no-disabled-tests it.skip("skipped and requeued paths should be visited", function() { const ast = parse("id"); From 84767b124b31d061d9a6cf856f00de3638f02124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 9 Feb 2020 23:34:40 -0500 Subject: [PATCH 3/3] chore: suppress preset-env debug log when linting --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d1b6415230f8..6e4ec4bbf712 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ lint-ts-ci: bootstrap-flowcheck lint: lint-js lint-ts lint-js: - $(YARN) eslint scripts $(SOURCES) '*.js' --format=codeframe + BABEL_ENV=test $(YARN) eslint scripts $(SOURCES) '*.js' --format=codeframe lint-ts: scripts/lint-ts-typings.sh