Skip to content

Commit fda1444

Browse files
authored
fix(lint): refine standard-track exception handling (#29224)
* test(lint): ensure feature is exception * chore(lefthook): stage standard-track-exceptions changes * test(lint): wrap standard-track tests + use beforeEach/afterEach * test(status): use dummy feature key * test(status): restore comments
1 parent bc7746d commit fda1444

File tree

3 files changed

+73
-55
lines changed

3 files changed

+73
-55
lines changed

.lefthook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pre-commit:
1818
- .vscode/*.json
1919
- browsers/*.json
2020
- schemas/*.json
21-
run: npm run lint:fix {staged_files}
21+
run: npm run lint:fix {staged_files} && git add lint/common/standard-track-exceptions.txt
2222
stage_fixed: true
2323

2424
pre-push:

lint/linter/test-status.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const { browsers } = bcd;
1010
/** @import {Linter, LinterData} from '../types.js' */
1111
/** @import {Logger} from '../utils.js' */
1212
/** @import {BrowserName, CompatStatement} from '../../types/types.js' */
13-
const standardTrackExceptions = new Set(await getStandardTrackExceptions());
13+
export const standardTrackExceptions = new Set(
14+
await getStandardTrackExceptions(),
15+
);
1416

1517
// See: https://github.com/web-platform-dx/web-features/blob/main/docs/baseline.md#core-browser-set
1618
const CORE_BROWSER_SET = new Set([

lint/linter/test-status.test.js

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import assert from 'node:assert/strict';
77

88
import { Logger } from '../utils.js';
99

10-
import test, { checkExperimental } from './test-status.js';
10+
import test, {
11+
checkExperimental,
12+
standardTrackExceptions,
13+
} from './test-status.js';
1114

1215
describe('checkExperimental', () => {
1316
it('should return true when data is not experimental', () => {
@@ -211,68 +214,81 @@ describe('checkStatus', () => {
211214
assert.ok(logger.messages[0].message.includes('should be set to'));
212215
});
213216

214-
it('should not log error for features in exception list missing spec_url', () => {
215-
/** @type {CompatStatement} */
216-
const data = {
217-
status: {
218-
experimental: false,
219-
standard_track: true,
220-
deprecated: false,
221-
},
222-
support: {},
223-
};
217+
describe('standard-track-exceptions', () => {
218+
beforeEach(() => {
219+
standardTrackExceptions.add('api.Foo');
220+
});
224221

225-
// This feature is in the exception list
226-
test.check(logger, {
227-
data,
228-
path: { category: 'api', full: 'api.AudioProcessingEvent' },
222+
afterEach(() => {
223+
standardTrackExceptions.delete('api.Foo');
229224
});
230225

231-
assert.equal(logger.messages.length, 0);
232-
});
226+
it('should not log error for features in exception list missing spec_url', () => {
227+
/** @type {CompatStatement} */
228+
const data = {
229+
status: {
230+
experimental: false,
231+
standard_track: true,
232+
deprecated: false,
233+
},
234+
support: {},
235+
};
233236

234-
it('should log warning when exception no longer applies (has spec_url)', () => {
235-
/** @type {CompatStatement} */
236-
const data = {
237-
status: {
238-
experimental: false,
239-
standard_track: true,
240-
deprecated: false,
241-
},
242-
spec_url: 'https://example.com/spec',
243-
support: {},
244-
};
237+
test.check(logger, {
238+
data,
239+
path: { category: 'api', full: 'api.Foo' },
240+
});
245241

246-
// This feature is in the exception list but now has spec_url
247-
test.check(logger, {
248-
data,
249-
path: { category: 'api', full: 'api.AudioProcessingEvent' },
242+
// Feature is in the exception list.
243+
244+
assert.equal(logger.messages.length, 0);
250245
});
251246

252-
assert.equal(logger.messages.length, 1);
253-
assert.equal(logger.messages[0].level, 'warning');
254-
assert.ok(logger.messages[0].message.includes('exception list'));
255-
});
247+
it('should log warning when exception no longer applies (has spec_url)', () => {
248+
/** @type {CompatStatement} */
249+
const data = {
250+
status: {
251+
experimental: false,
252+
standard_track: true,
253+
deprecated: false,
254+
},
255+
spec_url: 'https://example.com/spec',
256+
support: {},
257+
};
256258

257-
it('should log warning when exception no longer applies (standard_track false)', () => {
258-
/** @type {CompatStatement} */
259-
const data = {
260-
status: {
261-
experimental: false,
262-
standard_track: false,
263-
deprecated: false,
264-
},
265-
support: {},
266-
};
259+
test.check(logger, {
260+
data,
261+
path: { category: 'api', full: 'api.Foo' },
262+
});
267263

268-
// This feature is in the exception list but standard_track is now false
269-
test.check(logger, {
270-
data,
271-
path: { category: 'api', full: 'api.AudioProcessingEvent' },
264+
// Feature is in the exception list but now has `spec_url`.
265+
266+
assert.equal(logger.messages.length, 1);
267+
assert.equal(logger.messages[0].level, 'warning');
268+
assert.ok(logger.messages[0].message.includes('exception list'));
272269
});
273270

274-
assert.equal(logger.messages.length, 1);
275-
assert.equal(logger.messages[0].level, 'warning');
276-
assert.ok(logger.messages[0].message.includes('exception list'));
271+
it('should log warning when exception no longer applies (standard_track false)', () => {
272+
/** @type {CompatStatement} */
273+
const data = {
274+
status: {
275+
experimental: false,
276+
standard_track: false,
277+
deprecated: false,
278+
},
279+
support: {},
280+
};
281+
282+
test.check(logger, {
283+
data,
284+
path: { category: 'api', full: 'api.Foo' },
285+
});
286+
287+
// Feature is in the exception list but `standard_track` is now false.
288+
289+
assert.equal(logger.messages.length, 1);
290+
assert.equal(logger.messages[0].level, 'warning');
291+
assert.ok(logger.messages[0].message.includes('exception list'));
292+
});
277293
});
278294
});

0 commit comments

Comments
 (0)