Skip to content
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

Fix no-disable regression for some rules #6018

Merged
merged 1 commit into from Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/utils/__tests__/report.test.js
Expand Up @@ -162,6 +162,28 @@ it('with relevant rule-specific disabledRange, among others', () => {
expect(v.result.warn).toHaveBeenCalledTimes(0);
});

it('with relevant rule-specific disabledRange with range report', () => {
const v = {
ruleName: 'foo',
result: {
warn: jest.fn(),
stylelint: {
disabledRanges: {
all: [],
foo: [{ start: 2, end: 2 }],
},
},
},
message: 'bar',
node: {
rangeBy: () => ({ start: { line: 2, column: 1 }, end: { line: 5, column: 1 } }),
},
};

report(v);
expect(v.result.warn).toHaveBeenCalledTimes(0);
});

it("with quiet mode on and rule severity of 'warning'", () => {
const v = {
ruleName: 'foo',
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/report.js
Expand Up @@ -28,12 +28,11 @@ module.exports = function report(problem) {
return;
}

const { start, end } = (node && node.rangeBy({ index, endIndex })) || {};
const { start } = (node && node.rangeBy({ index, endIndex })) || {};

// If a line is not passed, use the node.rangeBy method to get the
// line number that the complaint pertains to
const startLine = line || (start && start.line);
const endLine = line || (end && end.line);

if (!startLine) {
throw new Error('You must pass either a node or a line number');
Expand All @@ -50,7 +49,7 @@ module.exports = function report(problem) {
// and that disabledRange's rules include this one,
// do not register a warning
range.start <= startLine &&
(range.end === undefined || range.end >= (endLine || startLine)) &&
(range.end === undefined || range.end >= startLine) &&
(!range.rules || range.rules.includes(ruleName))
) {
// Collect disabled warnings
Expand Down