Skip to content

Commit

Permalink
Breaking: drop supports for ESLint 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jan 28, 2017
1 parent ba283df commit ecb7c49
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Additional ESLint's rules for Node.js
```

- Requires Node.js `^4.0.0 || >=6.0.0`
- Requires ESLint `>=2.0.0`
- Requires ESLint `>=3.1.0`

**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by [no-unsupported-features](docs/rules/no-unsupported-features.md) rule.

Expand Down
25 changes: 24 additions & 1 deletion lib/rules/exports-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ module.exports = {
context.options[1] != null &&
context.options[1].allowBatchAssign
)
const sourceCode = context.getSourceCode()

/**
* Gets the location info of reports.
*
* exports = foo
* ^^^^^^^^^
*
* module.exports = foo
* ^^^^^^^^^^^^^^^^
*
* @param {ASTNode} node - The node of `exports`/`module.exports`.
* @returns {Location} The location info of reports.
*/
function getLocation(node) {
const token = sourceCode.getTokenAfter(node)
return {
start: node.loc.start,
end: token.loc.end,
}
}

/**
* Enforces `module.exports`.
Expand All @@ -194,7 +215,7 @@ module.exports = {
// Report.
context.report({
node,
loc: node.loc,
loc: getLocation(node),
message:
"Unexpected access to 'exports'. " +
"Use 'module.exports' instead.",
Expand Down Expand Up @@ -231,6 +252,7 @@ module.exports = {
// Report.
context.report({
node,
loc: getLocation(node),
message:
"Unexpected access to 'module.exports'. " +
"Use 'exports' instead.",
Expand All @@ -252,6 +274,7 @@ module.exports = {
// Report.
context.report({
node,
loc: getLocation(node),
message:
"Unexpected assignment to 'exports'. " +
"Don't modify 'exports' itself.",
Expand Down
20 changes: 20 additions & 0 deletions lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ function findVariable(node, initialScope) {
return null
}

/**
* Gets the top member expression node.
*
* @param {ASTNode} identifier - The node to get.
* @returns {ASTNode} The top member expression node.
*/
function getTopMemberExpression(identifier) {
if (identifier.type !== "Identifier" && identifier.type !== "Literal") {
return identifier
}

let node = identifier
while (node.parent.type === "MemberExpression") {
node = node.parent
}

return node
}

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -165,6 +184,7 @@ module.exports = function(context) {
function report(node, name, info) {
context.report({
node,
loc: getTopMemberExpression(node).loc,
message: "{{name}} was deprecated since v{{version}}.{{replace}}",
data: {
name,
Expand Down
1 change: 1 addition & 0 deletions lib/util/check-existence.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = function checkForExistence(context, filePath, targets) {

context.report({
node: target.node,
loc: target.node.loc,
message: "\"{{name}}\" is not found.",
data: target,
})
Expand Down
2 changes: 2 additions & 0 deletions lib/util/check-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = function checkForPublish(context, filePath, targets) {
) {
context.report({
node: target.node,
loc: target.node.loc,
message: "\"{{name}}\" is not published.",
data: {name: target.moduleName},
})
Expand All @@ -86,6 +87,7 @@ module.exports = function checkForPublish(context, filePath, targets) {
) {
context.report({
node: target.node,
loc: target.node.loc,
message: "\"{{name}}\" is not published.",
data: {name: target.moduleName || target.name},
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"node": ">=4"
},
"peerDependencies": {
"eslint": ">=2.0.0"
"eslint": ">=3.1.0"
},
"dependencies": {
"ignore": "^3.0.11",
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ ruleTester.run("no-unsupported-features", rule, [
},
{
filename: fixture("gte-4.0.0/a.js"),
code: "var a = async () => 1 //NOT_SUPPORTED_ON_2",
code: "var a = async () => 1",
parserOptions: {ecmaVersion: 2017},
options: [{ignores: ["asyncAwait"]}],
},
Expand Down

0 comments on commit ecb7c49

Please sign in to comment.