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

Add linter for support blocks filled only with false #6809

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a8963eb
Lint data with no support history
saschanaz Oct 3, 2020
ce31c5c
suggestion to add a tracking bug
saschanaz Oct 28, 2020
10b40c9
fix tracking bug check
saschanaz May 22, 2021
c566ebf
cover nulls too
saschanaz Jun 9, 2021
36c3068
Merge remote-tracking branch 'upstream/main' into lint-nosupport
saschanaz May 8, 2022
d72fd37
Adjust error message
saschanaz May 8, 2022
207f929
Merge branch 'main' into lint-nosupport
saschanaz May 8, 2022
da39093
include fixer
saschanaz May 8, 2022
a757d95
Merge remote-tracking branch 'upstream/main' into lint-nosupport
saschanaz May 14, 2022
62eabfa
import fix
saschanaz May 14, 2022
05ed1b3
import fix 2
saschanaz May 15, 2022
56fe4ce
Merge remote-tracking branch 'upstream/main' into lint-nosupport
saschanaz May 19, 2022
800a24c
merge
saschanaz May 19, 2022
6a6f80b
Merge branch 'main' into lint-nosupport
saschanaz May 23, 2022
e71e704
Merge remote-tracking branch 'upstream/main' into lint-nosupport
saschanaz May 23, 2022
9881e89
Merge branch 'main' into lint-nosupport
saschanaz Jun 22, 2022
13c3027
Update test/linter/test-support-history.ts
saschanaz Jun 23, 2022
7dd52fe
Merge branch 'main' into lint-nosupport
saschanaz Jun 23, 2022
b47fed0
Merge branch 'main' into lint-nosupport
queengooborg Jul 11, 2022
1862692
Fix copyright, imports, formatting, variables
queengooborg Jul 11, 2022
b4bb03a
Merge branch 'main' into lint-nosupport
queengooborg Jul 11, 2022
18f4f86
Merge branch 'main' into lint-nosupport
saschanaz Nov 24, 2022
f507bd9
reformat
saschanaz Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/fix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import fixPropertyOrder from './property-order.js';
import fixStatementOrder from './statement-order.js';
import fixLinks from './links.js';
import fixStatus from './status.js';
import fixSupportHistory from './support-history.js';

const dirname = fileURLToPath(new URL('.', import.meta.url));

Expand Down Expand Up @@ -40,6 +41,7 @@ function load(...files: string[]): void {
fixStatementOrder(file);
fixLinks(file);
fixStatus(file);
fixSupportHistory(file);
}

continue;
Expand Down
44 changes: 44 additions & 0 deletions scripts/fix/support-history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */

import { readFileSync, writeFileSync, unlinkSync } from 'node:fs';
import { hasSupportHistory } from '../../test/linter/test-support-history';

/**
* @param {Identifier} data
*/
function check(data) {
let hasIssue = false;
if (data.__compat && !hasSupportHistory(data)) {
hasIssue = true;
}
for (const member in data) {
if (member === '__compat') {
continue;
}
if (check(data[member])) {
delete data[member];
}
}
return hasIssue;
}

function fixSupportHistory(filename: string) {
const actual = readFileSync(filename, 'utf-8').trim();
const data = JSON.parse(actual);

check(data);
const expected = JSON.stringify(data, null, 2);

let target = data;
while (Object.keys(target).length === 1) {
target = Object.values(target)[0];
}
if (Object.keys(target).length) {
writeFileSync(filename, expected + '\n', 'utf-8');
} else {
unlinkSync(filename);
}
}

export default fixSupportHistory;
2 changes: 2 additions & 0 deletions test/linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import testSchema from './test-schema.js';
import testSpecURLs from './test-spec-urls.js';
import testStatus from './test-status.js';
import testStyle from './test-style.js';
import testSupportHistory from './test-support-history.js';
import testVersions from './test-versions.js';

export default new Linters([
Expand All @@ -30,5 +31,6 @@ export default new Linters([
testSpecURLs,
testStatus,
testStyle,
testSupportHistory,
testVersions,
]);
45 changes: 45 additions & 0 deletions test/linter/test-support-history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import chalk from 'chalk-template';
import { Linter, Logger } from '../utils.js';

import type {
CompatStatement,
SimpleSupportStatement,
} from '../../types/types';

function stringOrArrayIncludes(
target: SimpleSupportStatement['notes'],
str: string,
) {
if (!target) {
return false;
}
if (Array.isArray(target)) {
return target.some((item) => item.includes(str));
}
return target.includes(str);
}

function includesTrackingBug(statement: SimpleSupportStatement) {
return (
stringOrArrayIncludes(statement.notes, 'crbug.com') ||
stringOrArrayIncludes(statement.notes, 'bugzil.la') ||
stringOrArrayIncludes(statement.notes, 'webkit.org/b/')
);
}

export function hasSupportHistory(compat: CompatStatement) {
return Object.values(compat.support).some(
(c) => Array.isArray(c) || !!c.version_added || includesTrackingBug(c),
);
}

export default {
name: 'Support history',
description: 'Ensure that prefixes in support statements are valid',
saschanaz marked this conversation as resolved.
Show resolved Hide resolved
scope: 'feature',
check(logger: Logger, { data }: { data: CompatStatement }) {
if (!hasSupportHistory(data)) {
logger.error(chalk`No support and no tracking bug`);
}
},
} as Linter;