-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: implement rfc 2021-suppression-support #15459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It looks like there are several file conflicts. Can you please take a look? |
88707fa
to
e80163e
Compare
Conflicts resolved. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks pretty good. A few things that jumped out to me.
while ( | ||
nextDirectiveIndex < options.directives.length && | ||
compareLocations(options.directives[nextDirectiveIndex], problem) <= 0 | ||
) { | ||
const directive = options.directives[nextDirectiveIndex++]; | ||
const suppression = { kind: "directive", justification: directive.unprocessedDirective.justification }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add location information to the suppression to show where the directive is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea. The location info can be leveraged for auditing purposes as well. I also find a location property in suppressions
in the SARIF format.
But I'd like to add location info to the suppressions in another PR because:
- The type
location
insuppressions
is needed to be discussed. Shall we use theline
and thecolumn
inunprocessedDirective
directly or we use the similar structure inLintMessage
(line
/column
/endLine
/endColumn
)? - This PR is huge enough due to a lot of modification in core logic and tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't work as expected with processors.
For example, I was testing with eslint-plugin-markdown.
.eslintrc.js:
module.exports = {
plugins: ["markdown"],
rules: {
"no-undef": 2
},
overrides: [
{
files: ["**/*.md"],
processor: "markdown/markdown"
}
]
};
test.md:
```js
a;
```
```js
b;
```
D:\tmp\suppressions\eslint>npx eslint test.md
D:\tmp\suppressions\eslint\test.md
2:1 error 'a' is not defined no-undef
6:1 error 'b' is not defined no-undef
✖ 2 problems (2 errors, 0 warnings)
Then, if we suppress those two problems:
```js
a; // eslint-disable-line
```
```js
b; // eslint-disable-line
```
D:\tmp\suppressions\eslint>npx eslint test.md -f json > results.json
results.json:
[
{
"filePath": "D:\\tmp\\suppressions\\eslint\\test.md",
"messages": [],
"suppressedMessages": [
{
"ruleId": "no-undef",
"severity": 2,
"message": "'b' is not defined.",
"line": 1,
"column": 1,
"nodeType": "Identifier",
"messageId": "undef",
"endLine": 1,
"endColumn": 2,
"suppressions": [
{
"kind": "directive",
"justification": ""
}
]
}
],
"errorCount": 0,
"fatalErrorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"usedDeprecatedRules": []
}
]
What doesn't look right in the output:
- There's only one suppressed message instead of two (
slots.lastSuppressedMessages
had only messages from the last code block). line
andendLine
should be 6 instead of 1 (the message was not postprocessed, so the location wasn't adjusted).
@mdjermanovic Thanks for pointing out! I moved |
docs/developer-guide/nodejs-api.md
Outdated
* [EditInfo type][editinfo] | ||
* [Formatter type][formatter] | ||
* [SourceCode](#sourcecode) | ||
* [splitLines()](#sourcecodesplitlines) | ||
* [Linter](#linter) | ||
* [verify()](#linterverify) | ||
* [verifyAndFix()](#linterverifyandfix) | ||
* [getSuppressedMessages()](#getsuppressedmessages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link is broken as there's no getsuppressedmessages
section in the document.
Lines 514 to 519 in 851f1f1
I think the expected behavior would be to include rules that appear in @nzakas what do you think about this? |
Thoughts? |
I agree. We want to be sure all rules represented in a formatter have access to the related meta info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Since this is a big change in the core, I'd certainly like someone else to review it too before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks so much for your hard work on this. Excellent job!
Thanks for contributing! This will be released tomorrow in ESLint v8.8.0 |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Implemented the RFC 2021-suppression-support.
Related issue #14784.
Is there anything you'd like reviewers to focus on?