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

Commit

Permalink
Pass correct scope analyzer options
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Dec 25, 2017
1 parent 00978ec commit 7279b37
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
13 changes: 8 additions & 5 deletions lib/analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ class Referencer extends OriginalReferencer {
}

module.exports = function(ast, parserOptions) {
if (OriginalReferencer._babelEslintPatched) {
return escope.analyze(ast, parserOptions);
}

const options = {
optimistic: false,
directive: false,
Expand All @@ -322,9 +318,16 @@ module.exports = function(ast, parserOptions) {
impliedStrict: false,
sourceType: ast.sourceType,
ecmaVersion: parserOptions.ecmaVersion || 6,
childVisitorKeys,
fallback,
};

if (OriginalReferencer._babelEslintPatched) {
options._skipBabelEslintGlobals = true;
return escope.analyze(ast, options);
}

options.childVisitorKeys = childVisitorKeys;

const scopeManager = new escope.ScopeManager(options);
const referencer = new Referencer(options, scopeManager);

Expand Down
15 changes: 8 additions & 7 deletions lib/parse-with-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ function monkeypatch(modules) {

var analyze = escope.analyze;
escope.analyze = function(ast, opts) {
opts = opts || {};
opts.ecmaVersion = eslintOptions.ecmaVersion;
opts.sourceType = eslintOptions.sourceType;
if (eslintOptions.globalReturn !== undefined) {
opts.nodejsScope = eslintOptions.globalReturn;
if (!opts || !opts._skipBabelEslintGlobals) {
opts = opts || {};
opts.ecmaVersion = eslintOptions.ecmaVersion;
opts.sourceType = eslintOptions.sourceType;
if (eslintOptions.globalReturn !== undefined) {
opts.nodejsScope = eslintOptions.globalReturn;
}
}

var results = analyze.call(this, ast, opts);
return results;
return analyze.call(this, ast, opts);
};

// if there are decorators, then visit each
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@babel/traverse": "7.0.0-beta.31",
"@babel/types": "7.0.0-beta.31",
"babylon": "7.0.0-beta.31",
"eslint-old": "npm:eslint@4.13.1",
"eslint-scope": "~3.7.1",
"eslint-visitor-keys": "^1.0.0"
},
Expand Down
27 changes: 24 additions & 3 deletions test/non-regression.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/*eslint-env mocha*/
"use strict";
var eslint = require("eslint");
var oldEslint = require("eslint-old");
var unpad = require("dedent");

function verifyAndAssertMessages(
function verifyAndAssertMessagesWithSpecificESLint(
code,
rules,
expectedMessages,
sourceType,
overrideConfig
overrideConfig,
linter
) {
var config = {
parser: require.resolve(".."),
Expand All @@ -34,7 +36,7 @@ function verifyAndAssertMessages(
}
}

var messages = eslint.linter.verify(code, config);
var messages = linter.verify(code, config);

if (messages.length !== expectedMessages.length) {
throw new Error(
Expand Down Expand Up @@ -62,6 +64,25 @@ function verifyAndAssertMessages(
});
}

function verifyAndAssertMessages(
code,
rules,
expectedMessages,
sourceType,
overrideConfig
) {
[new eslint.Linter(), new oldEslint.Linter()].forEach(linter => {
verifyAndAssertMessagesWithSpecificESLint(
code,
rules,
expectedMessages,
sourceType,
overrideConfig,
linter
);
});
}

describe("verify", () => {
it("arrow function support (issue #1)", () => {
verifyAndAssertMessages("describe('stuff', () => {});", {}, []);
Expand Down
44 changes: 43 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,48 @@ eslint-module-utils@^2.1.1:
debug "^2.6.8"
pkg-dir "^1.0.0"

"eslint-old@npm:eslint@4.13.1":
version "4.13.1"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.13.1.tgz#0055e0014464c7eb7878caf549ef2941992b444f"
dependencies:
ajv "^5.3.0"
babel-code-frame "^6.22.0"
chalk "^2.1.0"
concat-stream "^1.6.0"
cross-spawn "^5.1.0"
debug "^3.0.1"
doctrine "^2.0.2"
eslint-scope "^3.7.1"
espree "^3.5.2"
esquery "^1.0.0"
estraverse "^4.2.0"
esutils "^2.0.2"
file-entry-cache "^2.0.0"
functional-red-black-tree "^1.0.1"
glob "^7.1.2"
globals "^11.0.1"
ignore "^3.3.3"
imurmurhash "^0.1.4"
inquirer "^3.0.6"
is-resolvable "^1.0.0"
js-yaml "^3.9.1"
json-stable-stringify-without-jsonify "^1.0.1"
levn "^0.3.0"
lodash "^4.17.4"
minimatch "^3.0.2"
mkdirp "^0.5.1"
natural-compare "^1.4.0"
optionator "^0.8.2"
path-is-inside "^1.0.2"
pluralize "^7.0.0"
progress "^2.0.0"
require-uncached "^1.0.3"
semver "^5.3.0"
strip-ansi "^4.0.0"
strip-json-comments "~2.0.1"
table "^4.0.1"
text-table "~0.2.0"

eslint-plugin-flowtype@^2.30.3:
version "2.34.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.34.0.tgz#b9875f314652e5081623c9d2b18a346bbb759c09"
Expand Down Expand Up @@ -592,7 +634,7 @@ esrecurse@^4.1.0:
estraverse "^4.1.0"
object-assign "^4.0.1"

estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1:
estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

Expand Down

0 comments on commit 7279b37

Please sign in to comment.