diff --git a/.lefthook.yml b/.lefthook.yml index 9b5e8289a17d96..44aaba7f363ea5 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -18,7 +18,7 @@ pre-commit: - .vscode/*.json - browsers/*.json - schemas/*.json - run: npm run lint:fix {staged_files} + run: npm run lint:fix {staged_files} && git add lint/common/standard-track-exceptions.txt stage_fixed: true pre-push: diff --git a/lint/linter/test-status.js b/lint/linter/test-status.js index 317dd94895458c..cfe87569e66401 100644 --- a/lint/linter/test-status.js +++ b/lint/linter/test-status.js @@ -10,7 +10,9 @@ const { browsers } = bcd; /** @import {Linter, LinterData} from '../types.js' */ /** @import {Logger} from '../utils.js' */ /** @import {BrowserName, CompatStatement} from '../../types/types.js' */ -const standardTrackExceptions = new Set(await getStandardTrackExceptions()); +export const standardTrackExceptions = new Set( + await getStandardTrackExceptions(), +); // See: https://github.com/web-platform-dx/web-features/blob/main/docs/baseline.md#core-browser-set const CORE_BROWSER_SET = new Set([ diff --git a/lint/linter/test-status.test.js b/lint/linter/test-status.test.js index 354d1c522ba863..bf0b6a76dbefae 100644 --- a/lint/linter/test-status.test.js +++ b/lint/linter/test-status.test.js @@ -7,7 +7,10 @@ import assert from 'node:assert/strict'; import { Logger } from '../utils.js'; -import test, { checkExperimental } from './test-status.js'; +import test, { + checkExperimental, + standardTrackExceptions, +} from './test-status.js'; describe('checkExperimental', () => { it('should return true when data is not experimental', () => { @@ -211,68 +214,81 @@ describe('checkStatus', () => { assert.ok(logger.messages[0].message.includes('should be set to')); }); - it('should not log error for features in exception list missing spec_url', () => { - /** @type {CompatStatement} */ - const data = { - status: { - experimental: false, - standard_track: true, - deprecated: false, - }, - support: {}, - }; + describe('standard-track-exceptions', () => { + beforeEach(() => { + standardTrackExceptions.add('api.Foo'); + }); - // This feature is in the exception list - test.check(logger, { - data, - path: { category: 'api', full: 'api.AudioProcessingEvent' }, + afterEach(() => { + standardTrackExceptions.delete('api.Foo'); }); - assert.equal(logger.messages.length, 0); - }); + it('should not log error for features in exception list missing spec_url', () => { + /** @type {CompatStatement} */ + const data = { + status: { + experimental: false, + standard_track: true, + deprecated: false, + }, + support: {}, + }; - it('should log warning when exception no longer applies (has spec_url)', () => { - /** @type {CompatStatement} */ - const data = { - status: { - experimental: false, - standard_track: true, - deprecated: false, - }, - spec_url: 'https://example.com/spec', - support: {}, - }; + test.check(logger, { + data, + path: { category: 'api', full: 'api.Foo' }, + }); - // This feature is in the exception list but now has spec_url - test.check(logger, { - data, - path: { category: 'api', full: 'api.AudioProcessingEvent' }, + // Feature is in the exception list. + + assert.equal(logger.messages.length, 0); }); - assert.equal(logger.messages.length, 1); - assert.equal(logger.messages[0].level, 'warning'); - assert.ok(logger.messages[0].message.includes('exception list')); - }); + it('should log warning when exception no longer applies (has spec_url)', () => { + /** @type {CompatStatement} */ + const data = { + status: { + experimental: false, + standard_track: true, + deprecated: false, + }, + spec_url: 'https://example.com/spec', + support: {}, + }; - it('should log warning when exception no longer applies (standard_track false)', () => { - /** @type {CompatStatement} */ - const data = { - status: { - experimental: false, - standard_track: false, - deprecated: false, - }, - support: {}, - }; + test.check(logger, { + data, + path: { category: 'api', full: 'api.Foo' }, + }); - // This feature is in the exception list but standard_track is now false - test.check(logger, { - data, - path: { category: 'api', full: 'api.AudioProcessingEvent' }, + // Feature is in the exception list but now has `spec_url`. + + assert.equal(logger.messages.length, 1); + assert.equal(logger.messages[0].level, 'warning'); + assert.ok(logger.messages[0].message.includes('exception list')); }); - assert.equal(logger.messages.length, 1); - assert.equal(logger.messages[0].level, 'warning'); - assert.ok(logger.messages[0].message.includes('exception list')); + it('should log warning when exception no longer applies (standard_track false)', () => { + /** @type {CompatStatement} */ + const data = { + status: { + experimental: false, + standard_track: false, + deprecated: false, + }, + support: {}, + }; + + test.check(logger, { + data, + path: { category: 'api', full: 'api.Foo' }, + }); + + // Feature is in the exception list but `standard_track` is now false. + + assert.equal(logger.messages.length, 1); + assert.equal(logger.messages[0].level, 'warning'); + assert.ok(logger.messages[0].message.includes('exception list')); + }); }); });