Skip to content

Commit

Permalink
Fix no-disable regression for some rules (#6018)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Apr 17, 2022
1 parent 91c3601 commit ba35f87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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

0 comments on commit ba35f87

Please sign in to comment.