Skip to content

Commit

Permalink
Lint data with no support history
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Oct 28, 2020
1 parent 17557c3 commit 61c8eeb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
testVersions,
testConsistency,
testDescriptions,
testSupportHistory,
} = require('./linter/index.js');
const { IS_CI } = require('./utils.js');
const testCompareFeatures = require('./test-compare-features');
Expand Down Expand Up @@ -63,7 +64,8 @@ function load(...files) {
hasConsistencyErrors = false,
hasRealValueErrors = false,
hasPrefixErrors = false,
hasDescriptionsErrors = false;
hasDescriptionsErrors = false,
hasSupportHistoryErrors = false;
const relativeFilePath = path.relative(process.cwd(), file);

const spinner = ora({
Expand Down Expand Up @@ -103,6 +105,7 @@ function load(...files) {
hasRealValueErrors = testRealValues(file);
hasPrefixErrors = testPrefix(file);
hasDescriptionsErrors = testDescriptions(file);
hasSupportHistoryErrors = testSupportHistory(file);
}
} catch (e) {
hasSyntaxErrors = true;
Expand All @@ -120,6 +123,7 @@ function load(...files) {
hasRealValueErrors,
hasPrefixErrors,
hasDescriptionsErrors,
hasSupportHistoryErrors,
].some(x => !!x);

if (fileHasErrors) {
Expand Down
2 changes: 2 additions & 0 deletions test/linter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const testStyle = require('./test-style.js');
const testVersions = require('./test-versions.js');
const testConsistency = require('./test-consistency.js');
const testDescriptions = require('./test-descriptions.js');
const testSupportHistory = require('./test-support-history.js');

module.exports = {
testBrowsers,
Expand All @@ -19,4 +20,5 @@ module.exports = {
testVersions,
testConsistency,
testDescriptions,
testSupportHistory,
};
61 changes: 61 additions & 0 deletions test/linter/test-support-history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const chalk = require('chalk');
const { Logger } = require('./utils.js');

/**
* @typedef {import('../../types').Identifier} Identifier
*/

/**
* @param {import('../../types.js').SimpleSupportStatement} statement
*/
function includesTrackingBug(statement) {
return (
statement.notes?.includes('crbug.com') ||
statement.notes?.includes('bugzil.la') ||
statement.notes?.includes('webkit.org/b/')
);
}

/**
* @param {Identifier} data
*/
function hasSupportHistory(data) {
return Object.values(data.__compat.support).some(
c =>
Array.isArray(c) || c.version_added !== false || includesTrackingBug(c),
);
}

/**
* @param {Identifier} data
* @param {Logger} logger
*/
function checkSupport(data, logger, path = []) {
if (data.__compat && !hasSupportHistory(data)) {
logger.error(chalk`{red → No support history in ${path.join('.')}}`);
}
for (const member in data) {
if (member === '__compat') {
continue;
}
checkSupport(data[member], logger, [...path, member]);
}
}

/**
* @param {string} filename
* @returns {boolean} If the file contains errors
*/
function testSupportHistory(filename) {
/** @type {Identifier} */
const data = require(filename);

const logger = new Logger('Support history');

checkSupport(data, logger);

logger.emit();
return logger.hasErrors();
}

module.exports = testSupportHistory;

0 comments on commit 61c8eeb

Please sign in to comment.