Permalink
Cannot retrieve contributors at this time
69 lines (63 sloc)
2.08 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-eslint-comments/lib/rules/disable-enable-pair.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Toru Nagashima <https://github.com/mysticatea> | |
* See LICENSE file in root directory for full license. | |
*/ | |
"use strict" | |
const DisabledArea = require("../internal/disabled-area") | |
const utils = require("../internal/utils") | |
module.exports = { | |
meta: { | |
docs: { | |
description: | |
"require a `eslint-enable` comment for every `eslint-disable` comment", | |
category: "Best Practices", | |
recommended: true, | |
url: | |
"https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html", | |
}, | |
fixable: null, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowWholeFile: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
type: "suggestion", | |
}, | |
create(context) { | |
const allowWholeFile = | |
context.options[0] && context.options[0].allowWholeFile | |
const sourceCode = context.getSourceCode() | |
const disabledArea = DisabledArea.get(sourceCode) | |
return { | |
Program(node) { | |
if (allowWholeFile && node.body.length === 0) { | |
return | |
} | |
for (const area of disabledArea.areas) { | |
if (area.end != null) { | |
continue | |
} | |
if ( | |
allowWholeFile && | |
utils.lte(area.start, node.loc.start) | |
) { | |
continue | |
} | |
context.report({ | |
loc: utils.toRuleIdLocation(area.comment, area.ruleId), | |
message: area.ruleId | |
? "Requires 'eslint-enable' directive for '{{ruleId}}'." | |
: "Requires 'eslint-enable' directive.", | |
data: area, | |
}) | |
} | |
}, | |
} | |
}, | |
} |