Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: babel/babel-eslint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b9067fa4a643c003810d7f7735393961e0ec5bbc
Choose a base ref
...
head repository: babel/babel-eslint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4bd049e06e2c7ab31053020fc662f51bf6c179e3
Choose a head ref

Commits on Jun 29, 2018

  1. Breaking: Upgraded Babel to 7.0.0-beta.51 (#642)

    * Upgraded Babel to 7.0.0-beta.51, with changes to decorators
    
    * Removed support for Node 4 and added it for Node 10
    
    * nit: fix typo [skip ci]
    rubennorte authored and existentialism committed Jun 29, 2018
    Copy the full SHA
    15e8d6f View commit details
  2. 9.0.0-beta.1

    existentialism committed Jun 29, 2018
    Copy the full SHA
    4882b29 View commit details

Commits on Jul 6, 2018

  1. Upgrade Babel to v7.0.0-beta.52 (#650)

    * Upgrade Babel to v7.0.0-beta.52
    
    * Fixed failing test
    rubennorte authored and existentialism committed Jul 6, 2018
    Copy the full SHA
    8948d83 View commit details
  2. Copy the full SHA
    9b06e1f View commit details
  3. Merge pull request #645 from rubennorte/support-new-flow-syntax-in-sc…

    …ope-analysis
    
    Support new flow syntax in scope analysis
    rubennorte authored Jul 6, 2018
    Copy the full SHA
    198964b View commit details
  4. 9.0.0-beta.2

    existentialism committed Jul 6, 2018
    Copy the full SHA
    e0119e0 View commit details

Commits on Jul 12, 2018

  1. Copy the full SHA
    6a45632 View commit details
  2. update lock

    hzoo committed Jul 12, 2018
    Copy the full SHA
    74c5d62 View commit details
  3. 9.0.0-beta.3

    hzoo committed Jul 12, 2018
    Copy the full SHA
    bc97875 View commit details

Commits on Aug 21, 2018

  1. Copy the full SHA
    45938d9 View commit details
  2. Bump some devDeps

    existentialism committed Aug 21, 2018
    Copy the full SHA
    5856ff5 View commit details

Commits on Aug 23, 2018

  1. Add logical assignment plugin (#674)

    Fix #672
    borela authored and suchipi committed Aug 23, 2018
    Copy the full SHA
    0b36951 View commit details
  2. Docs: Make the default parserOptions more explicit (#673)

    In particular, previously the `.eslintrc` example implied that the default value for `codeFrame` was `false`, when in fact it is `true`:
    https://github.com/babel/babel-eslint/blob/v9.0.0-beta.3/lib/parse.js#L14
    edmorley authored and suchipi committed Aug 23, 2018
    Copy the full SHA
    3ece549 View commit details

Commits on Aug 27, 2018

  1. Copy the full SHA
    c7ee9ae View commit details
  2. 9.0.0

    hzoo committed Aug 27, 2018
    Copy the full SHA
    6aa8b6f View commit details

Commits on Sep 25, 2018

  1. Drop old monkeypatching behavior (#689)

    An alternative to adding a direct dep on estraverse (#685), let's just drop the old monkeypatching behavior.
    
    Closes #685, Closes #680
    existentialism authored and hzoo committed Sep 25, 2018
    Copy the full SHA
    c333bd6 View commit details
  2. Test eslint5, update peerDep (#690)

    * test against eslint 5
    * set peerDep
    hzoo authored Sep 25, 2018
    Copy the full SHA
    b400cb1 View commit details
  3. Treat type alias declarationlike function declaration (#584)

    A type alias shouldn't trigger a no-use-before-define warning just
    like a function declaration.
    
    Cyclic type dependencies are common when using flow.
    For instance: type Node<T> = { head: T; tail: Node<T> }
    
    Fixes #485
    joa authored and hzoo committed Sep 25, 2018
    Copy the full SHA
    020d012 View commit details
  4. test value should be switched

    hzoo committed Sep 25, 2018
    Copy the full SHA
    717fba7 View commit details
  5. 10.0.0

    hzoo committed Sep 25, 2018
    Copy the full SHA
    8f78e28 View commit details

Commits on Sep 27, 2018

  1. Revert #584 (#697)

    * Revert "Treat type alias declarationlike function declaration (#584)"
    
    This reverts commit 020d012.
    hzoo authored Sep 27, 2018
    Copy the full SHA
    98c1f13 View commit details
  2. 10.0.1

    hzoo committed Sep 27, 2018
    Copy the full SHA
    4cf0a21 View commit details

Commits on Jun 17, 2019

  1. Copy the full SHA
    0241b48 View commit details
  2. 10.0.2

    hzoo committed Jun 17, 2019
    Copy the full SHA
    48f6d78 View commit details

Commits on Aug 25, 2019

  1. Copy the full SHA
    354953d View commit details
  2. 10.0.3

    hzoo committed Aug 25, 2019
    Copy the full SHA
    183d13e View commit details

Commits on Feb 25, 2020

  1. Update Babel to ^7.7.0 and enable Flow enums parsing (#812)

    * Update Babel to ^7.7.0 and enable Flow enums parsing
    
    * Update comment about Espree Flow enums support
    
    * Add EnumDeclaration to scope analyzer
    
    * Add test for unused enum
    gkz authored Feb 25, 2020
    Copy the full SHA
    2c754a8 View commit details

Commits on Feb 26, 2020

  1. 10.1.0

    Kai Cataldo committed Feb 26, 2020
    Copy the full SHA
    4bd049e View commit details
Showing with 1,219 additions and 862 deletions.
  1. +1 −1 .travis.yml
  2. +4 −4 README.md
  3. +12 −9 lib/analyze-scope.js
  4. +1 −4 lib/index.js
  5. +0 −9 lib/parse-with-patch.js
  6. +11 −5 lib/parse.js
  7. +0 −374 lib/patch-eslint-scope.js
  8. +9 −0 lib/require-from-eslint.js
  9. +19 −17 package.json
  10. +12 −2 test/babel-eslint.js
  11. +0 −12 test/fixtures/use-eslint-old.js
  12. +1 −0 test/integration.js
  13. +130 −12 test/non-regression.js
  14. +1,019 −413 yarn.lock
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
sudo: false
language: node_js
node_js:
- "10"
- "8"
- "6"
- "4"

matrix:
fast_finish: true
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -79,9 +79,9 @@ Check out the [ESLint docs](http://eslint.org/docs/rules/) for all possible rule

### Configuration

`sourceType` can be set to `'module'`(default) or `'script'` if your code isn't using ECMAScript modules.
`allowImportExportEverywhere` can be set to true to allow import and export declarations to appear anywhere a statement is allowed if your build environment supports that. By default, import and export declarations can only appear at a program's top level.
`codeFrame` can be set to false to disable the code frame in the reporter. This is useful since some eslint formatters don't play well with it.
- `sourceType` can be set to `'module'`(default) or `'script'` if your code isn't using ECMAScript modules.
- `allowImportExportEverywhere` (default `false`) can be set to `true` to allow import and export declarations to appear anywhere a statement is allowed if your build environment supports that. Otherwise import and export declarations can only appear at a program's top level.
- `codeFrame` (default `true`) can be set to `false` to disable the code frame in the reporter. This is useful since some eslint formatters don't play well with it.

**.eslintrc**

@@ -91,7 +91,7 @@ Check out the [ESLint docs](http://eslint.org/docs/rules/) for all possible rule
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": false,
"codeFrame": false
"codeFrame": true
}
}
```
21 changes: 12 additions & 9 deletions lib/analyze-scope.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"use strict";

const t = require("@babel/types");
const escope = require("eslint-scope");
const Definition = require("eslint-scope/lib/definition").Definition;
const OriginalPatternVisitor = require("eslint-scope/lib/pattern-visitor");
const OriginalReferencer = require("eslint-scope/lib/referencer");
const requireFromESLint = require("./require-from-eslint");

const escope = requireFromESLint("eslint-scope");
const Definition = requireFromESLint("eslint-scope/lib/definition").Definition;
const OriginalPatternVisitor = requireFromESLint(
"eslint-scope/lib/pattern-visitor"
);
const OriginalReferencer = requireFromESLint("eslint-scope/lib/referencer");
const fallback = require("eslint-visitor-keys").getKeys;
const childVisitorKeys = require("./visitor-keys");

@@ -145,6 +149,10 @@ class Referencer extends OriginalReferencer {
}
}

EnumDeclaration(node) {
this._createScopeVariable(node, node.id);
}

TypeAlias(node) {
this._createScopeVariable(node, node.id);

@@ -327,11 +335,6 @@ module.exports = function(ast, parserOptions) {
fallback,
};

if (OriginalReferencer._babelEslintPatched) {
require("./patch-eslint-scope")(parserOptions);
return escope.analyze(ast, options);
}

options.childVisitorKeys = childVisitorKeys;

const scopeManager = new escope.ScopeManager(options);
5 changes: 1 addition & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -11,10 +11,7 @@ exports.parseForESLint = function(code, options) {
options.allowImportExportEverywhere =
options.allowImportExportEverywhere || false;

if (options.eslintVisitorKeys && options.eslintScopeManager) {
return require("./parse-with-scope")(code, options);
}
return { ast: require("./parse-with-patch")(code, options) };
return require("./parse-with-scope")(code, options);
};

exports.parseNoPatch = function(code, options) {
9 changes: 0 additions & 9 deletions lib/parse-with-patch.js

This file was deleted.

16 changes: 11 additions & 5 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use strict";

var babylonToEspree = require("./babylon-to-espree");
var parse = require("babylon").parse;
var tt = require("babylon").tokTypes;
var parse = require("@babel/parser").parse;
var tt = require("@babel/parser").tokTypes;
var traverse = require("@babel/traverse").default;
var codeFrameColumns = require("@babel/code-frame").codeFrameColumns;

module.exports = function(code, options) {
const legacyDecorators =
options.ecmaFeatures && options.ecmaFeatures.legacyDecorators;

var opts = {
codeFrame: options.hasOwnProperty("codeFrame") ? options.codeFrame : true,
sourceType: options.sourceType,
@@ -16,14 +19,16 @@ module.exports = function(code, options) {
ranges: true,
tokens: true,
plugins: [
"flow",
["flow", { all: true, enums: true }],
"jsx",
"estree",
"asyncFunctions",
"asyncGenerators",
"classConstructorCall",
"classProperties",
"decorators",
legacyDecorators
? "decorators-legacy"
: ["decorators", { decoratorsBeforeExport: false }],
"doExpressions",
"exponentiationOperator",
"exportDefaultFrom",
@@ -40,8 +45,9 @@ module.exports = function(code, options) {
"bigInt",
"optionalCatchBinding",
"throwExpressions",
"pipelineOperator",
["pipelineOperator", { proposal: "minimal" }],
"nullishCoalescingOperator",
"logicalAssignment",
],
};

374 changes: 0 additions & 374 deletions lib/patch-eslint-scope.js

This file was deleted.

9 changes: 9 additions & 0 deletions lib/require-from-eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const resolve = require("resolve");
const eslintBase = require.resolve("eslint");

module.exports = function requireFromESLint(id) {
const path = resolve.sync(id, { basedir: eslintBase });
return require(path);
};
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-eslint",
"version": "8.2.5",
"version": "10.1.0",
"description": "Custom parser for ESLint",
"main": "lib/index.js",
"files": [
@@ -11,43 +11,45 @@
"url": "https://github.com/babel/babel-eslint.git"
},
"dependencies": {
"@babel/code-frame": "7.0.0-beta.44",
"@babel/traverse": "7.0.0-beta.44",
"@babel/types": "7.0.0-beta.44",
"babylon": "7.0.0-beta.44",
"eslint-scope": "~3.7.1",
"eslint-visitor-keys": "^1.0.0"
"@babel/code-frame": "^7.0.0",
"@babel/parser": "^7.7.0",
"@babel/traverse": "^7.7.0",
"@babel/types": "^7.7.0",
"eslint-visitor-keys": "^1.0.0",
"resolve": "^1.12.0"
},
"scripts": {
"test": "npm run lint && npm run test-only",
"test-only": "mocha && mocha --require test/fixtures/preprocess-to-patch.js && mocha --require test/fixtures/use-eslint-old.js",
"lint": "eslint index.js babylon-to-espree test",
"fix": "eslint index.js babylon-to-espree test --fix",
"test-only": "mocha && mocha --require test/fixtures/preprocess-to-patch.js",
"lint": "eslint lib test",
"fix": "eslint lib test --fix",
"precommit": "lint-staged",
"preversion": "npm test",
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'"
},
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"license": "MIT",
"engines": {
"node": ">=4"
"node": ">=6"
},
"bugs": {
"url": "https://github.com/babel/babel-eslint/issues"
},
"homepage": "https://github.com/babel/babel-eslint",
"peerDependencies": {
"eslint": ">= 4.12.1"
},
"devDependencies": {
"babel-eslint": "^8.0.0",
"babel-eslint": "^8.2.6",
"dedent": "^0.7.0",
"eslint": "npm:eslint@4.19.1",
"eslint": "^5.6.0",
"eslint-config-babel": "^7.0.1",
"eslint-old": "npm:eslint@4.13.1",
"eslint-plugin-flowtype": "^2.30.3",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^2.1.2",
"espree": "^3.5.2",
"husky": "^0.14.0",
"lint-staged": "^6.1.1",
"husky": "^1.0.0-rc.13",
"lint-staged": "^7.2.2",
"mocha": "^5.0.1",
"prettier": "^1.4.4"
},
14 changes: 12 additions & 2 deletions test/babel-eslint.js
Original file line number Diff line number Diff line change
@@ -261,11 +261,11 @@ describe("babylon-to-espree", () => {
});

it("export named", () => {
parseAndAssertSame("export { foo };");
parseAndAssertSame("const foo = 1; export { foo };");
});

it("export named alias", () => {
parseAndAssertSame("export { foo as bar };");
parseAndAssertSame("const foo = 1; export { foo as bar };");
});

// Espree doesn't support the optional chaining operator yet
@@ -298,6 +298,16 @@ describe("babylon-to-espree", () => {
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
});

// Espree doesn't support Flow enums
it("flow enums", () => {
const code = "enum E {A, B}";
const babylonAST = babelEslint.parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
}).ast;
assert.strictEqual(babylonAST.body[0].type, "EnumDeclaration");
});

it.skip("empty program with line comment", () => {
parseAndAssertSame("// single comment");
});
12 changes: 0 additions & 12 deletions test/fixtures/use-eslint-old.js

This file was deleted.

1 change: 1 addition & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -225,6 +225,7 @@ function strictSuite() {
// Strip chalk colors, these are not relevant for the test
const stripAnsi = str =>
str.replace(
// eslint-disable-next-line no-control-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
);
142 changes: 130 additions & 12 deletions test/non-regression.js
Original file line number Diff line number Diff line change
@@ -229,6 +229,24 @@ describe("verify", () => {
);
});

it("enum declaration", () => {
verifyAndAssertMessages(
`
enum E {
A,
B,
}
E.A;
enum UnusedEnum {
A,
B,
}
`,
{ "no-unused-vars": 1, "no-undef": 1 },
["6:6 'UnusedEnum' is defined but never used. no-unused-vars"]
);
});

it("type parameter bounds (classes)", () => {
verifyAndAssertMessages(
`
@@ -476,7 +494,7 @@ describe("verify", () => {
);
});

it("polymorphpic types #109", () => {
it("polymorphic types #109", () => {
verifyAndAssertMessages(
"export default function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> { n; }",
{ "no-unused-vars": 1, "no-undef": 1 }
@@ -494,7 +512,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types for class #123", () => {
it("polymorphic/generic types for class #123", () => {
verifyAndAssertMessages(
`
class Box<T> {
@@ -507,7 +525,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types for function #123", () => {
it("polymorphic/generic types for function #123", () => {
verifyAndAssertMessages(
`
export function identity<T>(value) {
@@ -518,7 +536,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types for type alias #123", () => {
it("polymorphic/generic types for type alias #123", () => {
verifyAndAssertMessages(
`
import Bar from './Bar';
@@ -528,7 +546,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types - outside of fn scope #123", () => {
it("polymorphic/generic types - outside of fn scope #123", () => {
verifyAndAssertMessages(
`
export function foo<T>(value) { value; };
@@ -542,7 +560,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types - extending unknown #123", () => {
it("polymorphic/generic types - extending unknown #123", () => {
verifyAndAssertMessages(
`
import Bar from 'bar';
@@ -553,6 +571,28 @@ describe("verify", () => {
);
});

it("polymorphic/generic types - function calls", () => {
verifyAndAssertMessages(
`
function f<T>(): T {}
f<T>();
`,
{ "no-unused-vars": 1, "no-undef": 1 },
["2:3 'T' is not defined. no-undef"]
);
});

it("polymorphic/generic types - function calls #644", () => {
verifyAndAssertMessages(
`
import type {Type} from 'Type';
function f<T>(): T {}
f<Type>();
`,
{ "no-unused-vars": 1, "no-undef": 1 }
);
});

it("support declarations #132", () => {
verifyAndAssertMessages(
`
@@ -1124,9 +1164,32 @@ describe("verify", () => {
);
});

describe("decorators #72", () => {
describe("decorators #72 (legacy)", () => {
function verifyDecoratorsLegacyAndAssertMessages(
code,
rules,
expectedMessages,
sourceType
) {
const overrideConfig = {
parserOptions: {
ecmaFeatures: {
legacyDecorators: true,
},
sourceType,
},
};
return verifyAndAssertMessages(
code,
rules,
expectedMessages,
sourceType,
overrideConfig
);
}

it("class declaration", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classDeclaration from 'decorator';
import decoratorParameter from 'decorator';
@@ -1140,7 +1203,7 @@ describe("verify", () => {
});

it("method definition", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
@@ -1158,7 +1221,7 @@ describe("verify", () => {
});

it("method definition get/set", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
@@ -1178,7 +1241,7 @@ describe("verify", () => {
});

it("object property", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
@@ -1197,7 +1260,7 @@ describe("verify", () => {
});

it("object property get/set", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
@@ -1218,6 +1281,61 @@ describe("verify", () => {
});
});

describe("decorators #72", () => {
it("class declaration", () => {
verifyAndAssertMessages(
`
import classDeclaration from 'decorator';
import decoratorParameter from 'decorator';
export
@classDeclaration((parameter) => parameter)
@classDeclaration(decoratorParameter)
@classDeclaration
class TextareaAutosize {}
`,
{ "no-unused-vars": 1 }
);
});

it("method definition", () => {
verifyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
export class TextareaAutosize {
@classMethodDeclarationA((parameter) => parameter)
@classMethodDeclarationA(decoratorParameter)
@classMethodDeclarationA
methodDeclaration(e) {
e();
}
}
`,
{ "no-unused-vars": 1 }
);
});

it("method definition get/set", () => {
verifyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
export class TextareaAutosize {
@classMethodDeclarationA((parameter) => parameter)
@classMethodDeclarationA(decoratorParameter)
@classMethodDeclarationA
get bar() { }
@classMethodDeclarationA((parameter) => parameter)
@classMethodDeclarationA(decoratorParameter)
@classMethodDeclarationA
set bar(val) { val; }
}
`,
{ "no-unused-vars": 1 }
);
});
});

it("detects minimal no-unused-vars case #120", () => {
verifyAndAssertMessages("var unused;", { "no-unused-vars": 1 }, [
"1:5 'unused' is defined but never used. no-unused-vars",
1,432 changes: 1,019 additions & 413 deletions yarn.lock

Large diffs are not rendered by default.