Skip to content

Commit

Permalink
@babel/eslint-plugin: Update rules/tests to use @babel/eslint-parser (#…
Browse files Browse the repository at this point in the history
…10977)

* Use @babel/eslint-parser for tests

* Update rules/tests

* Update docs

* add @babel/eslint-shared-fixtures to package.json

* remove bug fix

* convert RuleTester to ESM

* Update devDep versions
  • Loading branch information
kaicataldo authored and nicolo-ribaudo committed Jan 11, 2020
1 parent 81c5f1f commit d8e6219
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 3,878 deletions.
18 changes: 2 additions & 16 deletions eslint/babel-eslint-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,16 @@
"main": "lib/index.js",
"peerDependencies": {
"@babel/core": ">=7.2.0",
"eslint": ">= 6.0.0"
"eslint": ">=6.0.0"
},
"dependencies": {
"eslint-scope": "5.0.0",
"eslint-visitor-keys": "^1.1.0",
"semver": "^6.3.0"
},
"devDependencies": {
"@babel/eslint-shared-fixtures": "*",
"@babel/core": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-private-methods": "^7.7.4",
"@babel/plugin-syntax-bigint": "^7.7.4",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-export-default-from": "^7.0.0",
"@babel/plugin-syntax-export-namespace-from": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-syntax-numeric-separator": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"dedent": "^0.7.0",
"eslint": "^6.0.1",
"espree": "^6.0.0"
Expand Down
5 changes: 3 additions & 2 deletions eslint/babel-eslint-parser/test/babel-eslint-parser.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import assert from "assert";
import path from "path";
import espree from "espree";
import escope from "eslint-scope";
import unpad from "dedent";
import { parseForESLint } from "../src";
import assertImplementsAST from "./helpers/assert-implements-ast";

const babelOptions = {
configFile: path.resolve(__dirname, "./fixtures/config/babel.config.js"),
configFile: require.resolve(
"@babel/eslint-shared-fixtures/config/babel.config.js",
),
};

function parseAndAssertSame(code) {
Expand Down
10 changes: 4 additions & 6 deletions eslint/babel-eslint-parser/test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ function verifyAndAssertMessagesWithSpecificESLint(
sourceType,
requireConfigFile: false,
babelOptions: {
configFile: path.resolve(
__dirname,
"./fixtures/config/babel.config.js",
configFile: require.resolve(
"@babel/eslint-shared-fixtures/config/babel.config.js",
),
},
...overrideConfig?.parserOptions,
Expand Down Expand Up @@ -1157,9 +1156,8 @@ describe("verify", () => {
parserOptions: {
sourceType,
babelOptions: {
configFile: path.resolve(
__dirname,
"./fixtures/config/babel.config.decorators-legacy.js",
configFile: require.resolve(
"@babel/eslint-shared-fixtures/config/babel.config.decorators-legacy.js",
),
},
},
Expand Down
16 changes: 7 additions & 9 deletions eslint/babel-eslint-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @babel/eslint-plugin

Companion rules for `@babel/eslint-parser`. `@babel/eslint-parser` does a great job at adapting `eslint`
for use with Babel, but it can't change the built in rules to support experimental features.
for use with Babel, but it can't change the built-in rules to support experimental features.
`@babel/eslint-plugin` re-implements problematic rules so they do not give false positives or negatives.

> Requires Node 10.9 or greater
Expand All @@ -26,7 +26,6 @@ original ones as well!).
```json
{
"rules": {
"babel/camelcase": "error",
"babel/new-cap": "error",
"babel/no-invalid-this": "error",
"babel/no-unused-expressions": "error",
Expand All @@ -37,13 +36,12 @@ original ones as well!).
```
### Rules

Each rule corresponds to a core `eslint` rule, and has the same options.
Each rule corresponds to a core `eslint` rule and has the same options.

🛠: means it's autofixable with `--fix`.

- `babel/camelcase: doesn't complain about optional chaining (`var foo = bar?.a_b;`)
- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`)
- `babel/no-invalid-this`: doesn't fail when inside class properties (`class A { a = this.b; }`)
- `babel/no-unused-expressions`: doesn't fail when using `do` expressions or [optional chaining](https://github.com/tc39/proposal-optional-chaining) (`a?.b()`).
- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠)
- `babel/semi`: doesn't fail when using `for await (let something of {})`. Includes class properties (🛠)
- `babel/new-cap`: handles decorators (`@Decorator`)
- `babel/no-invalid-this`: handles class fields and private class methods (`class A { a = this.b; }`)
- `babel/no-unused-expressions`: handles `do` expressions
- `babel/object-curly-spacing`: handles `export * as x from "mod";` (🛠)
- `babel/semi`: Handles class properties (🛠)
8 changes: 5 additions & 3 deletions eslint/babel-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
},
"homepage": "https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin",
"peerDependencies": {
"eslint": ">=4.0.0"
"@babel/eslint-parser": "0.0.0",
"eslint": ">=6.0.0"
},
"dependencies": {
"eslint-rule-composer": "^0.3.0"
},
"devDependencies": {
"babel-eslint": "^8.2.2",
"eslint": "^4.19.1",
"@babel/eslint-shared-fixtures": "*",
"@babel/eslint-parser": "*",
"eslint": "^6.0.0",
"lodash.clonedeep": "^4.5.0"
}
}
3 changes: 0 additions & 3 deletions eslint/babel-eslint-plugin/src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import newCap from "./rules/new-cap";
import camelcase from "./rules/camelcase";
import noInvalidThis from "./rules/no-invalid-this";
import noUnusedExpressions from "./rules/no-unused-expressions";
import objectCurlySpacing from "./rules/object-curly-spacing";
import semi from "./rules/semi";

module.exports = {
rules: {
camelcase,
"new-cap": newCap,
"no-invalid-this": noInvalidThis,
"no-unused-expressions": noUnusedExpressions,
"object-curly-spacing": objectCurlySpacing,
semi,
},
rulesConfig: {
camelcase: "off",
"new-cap": "off",
"no-invalid-this": "off",
"no-unused-expressions": "off",
Expand Down
231 changes: 0 additions & 231 deletions eslint/babel-eslint-plugin/src/rules/camelcase.js

This file was deleted.

0 comments on commit d8e6219

Please sign in to comment.