Skip to content

Commit

Permalink
Revive ESLint v1 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Dec 28, 2015
1 parent 79a2792 commit e39567b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 65 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ Some rules are slow because it searches `package.json` and opens it.

## Install & Usage

Currently, this is alpha versions for ESLint v2.

```
> npm install --save-dev eslint@next eslint-plugin-node
```

For ESLint v1, please use the specified version.

```
> npm install --save-dev eslint eslint-plugin-node@0.2
> npm install --save-dev eslint eslint-plugin-node
```

**.eslintrc**
Expand Down
24 changes: 12 additions & 12 deletions docs/rules/no-unsupported-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ The following patterns are considered problems:
/*eslint no-unsupported-features: [2, {version: 4}]*/
/*eslint-env es6*/

function foo(a = 1) { /*error Default Parameters are not supported yet on Node v4*/
function foo(a = 1) { /*error Default Parameters are not supported yet on Node v4.*/
//...
}

function foo(...a) { /*error Rest Parameters are not supported yet on Node v4*/
function foo(...a) { /*error Rest Parameters are not supported yet on Node v4.*/
//...
}

var a = [...b]; /*error Spread Operators are not supported yet on Node v4*/
var a = /foo/y; /*error RegExp "y" Flags are not supported yet on Node v4*/
var a = /foo/u; /*error RegExp "u" Flags are not supported yet on Node v4*/
var {a, b} = c; /*error Destructuring are not supported yet on Node v4*/
var {a, b} = c; /*error Destructuring are not supported yet on Node v4*/
var a = [...b]; /*error Spread Operators are not supported yet on Node v4.*/
var a = /foo/y; /*error RegExp "y" Flags are not supported yet on Node v4.*/
var a = /foo/u; /*error RegExp "u" Flags are not supported yet on Node v4.*/
var {a, b} = c; /*error Destructuring are not supported yet on Node v4.*/
var {a, b} = c; /*error Destructuring are not supported yet on Node v4.*/

let a = 1; /*error "let" Declarations in non-strict mode are not supported yet on Node v4*/
const a = 1; /*error "const" Declarations in non-strict mode are not supported yet on Node v4*/
class A {} /*error Classes in non-strict mode are not supported yet on Node v4*/
let a = 1; /*error "let" Declarations in non-strict mode are not supported yet on Node v4.*/
const a = 1; /*error "const" Declarations in non-strict mode are not supported yet on Node v4.*/
class A {} /*error Classes in non-strict mode are not supported yet on Node v4.*/

if (a) {
function foo() { /*error Block-Scoped Functions in non-strict mode are not supported yet on Node v4*/
function foo() { /*error Block-Scoped Functions in non-strict mode are not supported yet on Node v4.*/
//...
}
}

var p = new Proxy(o, { /*error Proxy is not supported yet on Node v4*/
var p = new Proxy(o, { /*error Proxy is not supported yet on Node v4.*/
//...
});
```
Expand Down
93 changes: 60 additions & 33 deletions lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,41 @@ function parseOptions(options) {
});
}

/**
* Checks whether or not the current configure has a special lexical environment.
* If it's modules or globalReturn then it has a special lexical environment.
*
* @param {RuleContext} context - A context to check.
* @returns {boolean} `true` if the current configure is modules or globalReturn.
*/
function checkSpecialLexicalEnvironment(context) {
var parserOptions = context.parserOptions;
var ecmaFeatures;

if (context.parserOptions) {
ecmaFeatures = parserOptions.ecmaFeatures;
return Boolean(
parserOptions.sourceType === "module" ||
(ecmaFeatures && ecmaFeatures.globalReturn)
);
}

// Backward Compatibility
ecmaFeatures = context.ecmaFeatures;
return Boolean(
ecmaFeatures &&
(ecmaFeatures.modules || ecmaFeatures.globalReturn)
);
}

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {
var sourceCode = context.getSourceCode();
var supportInfo = parseOptions(context.options[0]);
var hasSpecialLexicalEnvironment =
context.parserOptions.sourceType === "module" ||
Boolean(
context.parserOptions.ecmaFeatures &&
context.parserOptions.ecmaFeatures.globalReturn
);
var supportInfo = parseOptions(context.options[0] || 0.10);
var hasSpecialLexicalEnvironment = checkSpecialLexicalEnvironment(context);

/**
* Does an given action for each reference of the specified global variables.
Expand All @@ -108,6 +130,16 @@ module.exports = function(context) {

if (variable && variable.defs.length === 0) {
variable.references.forEach(f);

// Backward Compatibility
var references = globalScope.through;
for (var j = 0; j < references.length; ++j) {
var reference = references[j];

if (reference.identifier.name === name) {
f(reference);
}
}
}
}
}
Expand Down Expand Up @@ -369,30 +401,25 @@ module.exports = function(context) {
};
};

module.exports.schema = {
type: "array",
items: [
{oneOf: [
{
enum: VERSIONS
},
{
type: "object",
properties: {
version: {
enum: VERSIONS
},
ignores: {
type: "array",
items: {enum: OPTIONS},
uniqueItems: true
}
module.exports.schema = [
{oneOf: [
{
enum: VERSIONS
},
{
type: "object",
properties: {
version: {
enum: VERSIONS
},
additionalProperties: false,
required: ["version"]
}
]}
],
minItems: 1,
maxItems: 1
};
ignores: {
type: "array",
items: {enum: OPTIONS},
uniqueItems: true
}
},
additionalProperties: false,
required: ["version"]
}
]}
];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"coveralls": "cat coverage/lcov.info | coveralls"
},
"peerDependencies": {
"eslint": ">=2.0.0-alpha-2"
"eslint": ">=1.10.3"
},
"dependencies": {
"minimatch": "^3.0.0",
Expand All @@ -26,7 +26,7 @@
},
"devDependencies": {
"coveralls": "^2.11.4",
"eslint": "^2.0.0-alpha-2",
"eslint": "^1.10.3",
"eslint-config-eslint": "^1.0.1",
"istanbul": "^0.4.0",
"mocha": "^2.3.4",
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/no-missing-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,57 @@ ruleTester.run("no-missing-import", rule, {
filename: fixture("test.js"),
code: "import eslint from 'eslint';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("test.js"),
code: "import eslint from 'eslint/lib/ast-utils';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("test.js"),
code: "import a from './a';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("test.js"),
code: "import a from './a.js';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("test.js"),
code: "import resolve from 'resolve';",
options: [{"publish": "*.js"}],
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("test.js"),
code: "import mocha from 'mocha';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},

// Ignores it if the filename is unknown.
{
code: "import abc from 'no-exist-package-0';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
code: "import b from './b';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
}
],
Expand All @@ -91,6 +99,7 @@ ruleTester.run("no-missing-import", rule, {
filename: fixture("test.js"),
code: "import abc from 'no-exist-package-0';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: [
"\"no-exist-package-0\" is not found.",
Expand All @@ -101,6 +110,7 @@ ruleTester.run("no-missing-import", rule, {
filename: fixture("test.js"),
code: "import test from '@mysticatea/test';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: [
"\"@mysticatea/test\" is not found.",
Expand All @@ -112,27 +122,31 @@ ruleTester.run("no-missing-import", rule, {
code: "import abc from 'no-exist-package-0';",
options: [{"publish": null}],
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: ["\"no-exist-package-0\" is not found."]
},
{
filename: fixture("test.js"),
code: "import b from './b';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: ["\"./b\" is not found."]
},
{
filename: fixture("test.js"),
code: "import a from './a.json';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: ["\"./a.json\" is not found."]
},
{
filename: fixture("test.js"),
code: "import async from 'async';",
env: {node: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: ["\"async\" is not published."]
},
Expand All @@ -141,6 +155,7 @@ ruleTester.run("no-missing-import", rule, {
code: "import mocha from 'mocha';",
options: [{"publish": "*.js"}],
env: {node: true, es6: true},
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: ["\"mocha\" is not published."]
}
Expand Down
22 changes: 13 additions & 9 deletions tests/lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// Requirements
//------------------------------------------------------------------------------

var rule = require("../../../lib/rules/no-unsupported-features"),
RuleTester = require("eslint").RuleTester;
var rule = require("../../../lib/rules/no-unsupported-features");
var RuleTester = require("eslint").RuleTester;

//------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -51,19 +51,22 @@ function convertPattern(retv, pattern) {
code: "/*" + pattern.name + ": " + versionText + "*/ " + pattern.code,
env: {es6: true},
options: [version],
ecmaFeatures: {modules: Boolean(pattern.modules)},
parserOptions: {sourceType: pattern.modules ? "module" : "script"}
});
} else {
retv.valid.push({
code: "/*" + pattern.name + ": " + versionText + ", ignores: [\"" + pattern.key + "\"]*/ " + pattern.code,
env: {es6: true},
options: [{version: version, ignores: [pattern.key]}],
ecmaFeatures: {modules: Boolean(pattern.modules)},
parserOptions: {sourceType: pattern.modules ? "module" : "script"}
});
retv.invalid.push({
code: "/*" + pattern.name + ": " + versionText + "*/ " + pattern.code,
env: {es6: true},
options: [version],
ecmaFeatures: {modules: Boolean(pattern.modules)},
parserOptions: {sourceType: pattern.modules ? "module" : "script"},
errors: errors.map(function(message) { // eslint-disable-line no-loop-func
return message + versionText + ".";
Expand Down Expand Up @@ -172,13 +175,14 @@ ruleTester.run("no-unsupported-features", rule, [
errors: 2,
supported: NaN
},
{
key: "unicodeCodePointEscapes",
name: "Unicode Code Point Escapes",
code: "var \\u{102C0} = { \\u{102C0} : '\\u{1d306}' };",
errors: 3,
supported: 4
},
// TODO: ESLint cannot parse unicode code point escapes.
// {
// key: "unicodeCodePointEscapes",
// name: "Unicode Code Point Escapes",
// code: "var \\u{102C0} = { \\u{102C0} : '\\u{1d306}' };",
// errors: 3,
// supported: 4
// },
{
key: "newTarget",
name: "\"new.target\"",
Expand Down

0 comments on commit e39567b

Please sign in to comment.