From 6d1d005ee1e4e202235d4c2f1c54bc54ea267d7e Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Thu, 26 Mar 2020 19:29:27 -0700 Subject: [PATCH 1/7] Refactor: convert all functions to top-level arrow functions --- scripts/fix-feature-order.js | 4 +-- scripts/fix.js | 4 +-- scripts/mirror.js | 4 +-- scripts/traverse.js | 4 +-- test/lint.js | 4 +-- test/linter/test-browsers.js | 19 ++++++----- test/linter/test-consistency.js | 4 +-- test/linter/test-links.js | 12 +++---- test/linter/test-prefix.js | 12 +++---- test/linter/test-real-values.js | 58 ++++++++++++++++++--------------- test/linter/test-schema.js | 6 ++-- test/linter/test-style.js | 16 ++++----- test/linter/test-versions.js | 45 ++++++++++++------------- test/test-regexes.js | 8 ++--- test/test-utils.js | 4 +-- test/utils.js | 16 ++++----- 16 files changed, 114 insertions(+), 106 deletions(-) diff --git a/scripts/fix-feature-order.js b/scripts/fix-feature-order.js index 428dafad1ee804..543e9a74127dfb 100644 --- a/scripts/fix-feature-order.js +++ b/scripts/fix-feature-order.js @@ -25,7 +25,7 @@ const IS_WINDOWS = platform() === 'win32'; const compareFeatures = require('./compare-features'); -function orderFeatures(key, value) { +const orderFeatures = (key, value) => { if (value instanceof Object && '__compat' in value) { value = Object.keys(value) .sort(compareFeatures) @@ -35,7 +35,7 @@ function orderFeatures(key, value) { }, {}); } return value; -} +}; /** * @param {Promise} filename diff --git a/scripts/fix.js b/scripts/fix.js index a2550ae062240c..d9601c827bcc86 100644 --- a/scripts/fix.js +++ b/scripts/fix.js @@ -8,7 +8,7 @@ const format = require('./fix-format'); /** * @param {string[]} files */ -function load(...files) { +const load = (...files) => { for (let file of files) { if (file.indexOf(__dirname) !== 0) { file = path.resolve(__dirname, '..', file); @@ -34,7 +34,7 @@ function load(...files) { load(...subFiles); } -} +}; if (process.argv[2]) { load(process.argv[2]); diff --git a/scripts/mirror.js b/scripts/mirror.js index eb004f19881af6..c6b606534d852c 100644 --- a/scripts/mirror.js +++ b/scripts/mirror.js @@ -662,7 +662,7 @@ const setFeatureRecursive = (data, browser, source, modify) => { * @param {string} modify * @returns {boolean} */ -function mirrorDataByFile(browser, filepath, source, modify) { +const mirrorDataByFile = (browser, filepath, source, modify) => { let file = filepath; if (file.indexOf(__dirname) !== 0) { file = path.resolve(__dirname, '..', file); @@ -690,7 +690,7 @@ function mirrorDataByFile(browser, filepath, source, modify) { } return true; -} +}; /** * Allows mirroring by feature ID (e.g. "html.elements.a") diff --git a/scripts/traverse.js b/scripts/traverse.js index 10b419030c8438..d14a8321e8ff56 100644 --- a/scripts/traverse.js +++ b/scripts/traverse.js @@ -23,7 +23,7 @@ const { argv } = require('yargs').command( }, ); -function traverseFeatures(obj, depth, identifier) { +const traverseFeatures = (obj, depth, identifier) => { depth--; if (depth >= 0) { for (const i in obj) { @@ -54,7 +54,7 @@ function traverseFeatures(obj, depth, identifier) { } } } -} +}; let features = []; const folders = diff --git a/test/lint.js b/test/lint.js index 4d8379c7fd27e8..564d57af41d927 100644 --- a/test/lint.js +++ b/test/lint.js @@ -40,7 +40,7 @@ const argv = yargs * @param {string[]} files * @return {boolean} */ -function load(...files) { +const load = (...files) => { return files.reduce((prevHasErrors, file) => { if (file.indexOf(__dirname) !== 0) { file = path.resolve(__dirname, '..', file); @@ -139,7 +139,7 @@ function load(...files) { return load(...subFiles) || prevHasErrors; }, false); -} +}; /** @type {boolean} */ var hasErrors = argv.files diff --git a/test/linter/test-browsers.js b/test/linter/test-browsers.js index 2dba44a66efbcc..46d9553dd72b3c 100644 --- a/test/linter/test-browsers.js +++ b/test/linter/test-browsers.js @@ -26,6 +26,11 @@ const browsers = { 'webextensions-mobile': ['firefox_android'], }; +const hasVersionAddedOnly = statement => { + const keys = Object.keys(statement); + return keys.length === 1 && keys[0] === 'version_added'; +}; + /** * @param {Identifier} data * @param {string[]} displayBrowsers @@ -35,14 +40,14 @@ const browsers = { * @param {string} [path] * @returns {boolean} */ -function processData( +const processData = ( data, displayBrowsers, requiredBrowsers, category, logger, path = '', -) { +) => { if (data.__compat && data.__compat.support) { const support = data.__compat.support; @@ -72,10 +77,6 @@ function processData( const statementList = Array.isArray(supportStatement) ? supportStatement : [supportStatement]; - function hasVersionAddedOnly(statement) { - const keys = Object.keys(statement); - return keys.length === 1 && keys[0] === 'version_added'; - } let sawVersionAddedOnly = false; for (const statement of statementList) { if (hasVersionAddedOnly(statement)) { @@ -103,13 +104,13 @@ function processData( path && path.length > 0 ? `${path}.${key}` : key, ); } -} +}; /** * @param {string} filename * @returns {boolean} If the file contains errors */ -function testBrowsers(filename) { +const testBrowsers = filename => { const relativePath = path.relative( path.resolve(__dirname, '..', '..'), filename, @@ -165,6 +166,6 @@ function testBrowsers(filename) { return true; } return false; -} +}; module.exports = testBrowsers; diff --git a/test/linter/test-consistency.js b/test/linter/test-consistency.js index 6127202c328226..db90601ae16907 100644 --- a/test/linter/test-consistency.js +++ b/test/linter/test-consistency.js @@ -352,7 +352,7 @@ class ConsistencyChecker { /** * @param {string} filename */ -function testConsistency(filename) { +const testConsistency = filename => { /** @type {Identifier} */ let data = require(filename); @@ -398,6 +398,6 @@ function testConsistency(filename) { return true; } return false; -} +}; module.exports = testConsistency; diff --git a/test/linter/test-links.js b/test/linter/test-links.js index 8f9f36e1be447c..d217d6f46e2dfa 100644 --- a/test/linter/test-links.js +++ b/test/linter/test-links.js @@ -11,7 +11,7 @@ const { IS_WINDOWS, indexToPos, indexToPosRaw } = require('../utils.js'); * @param {string} filename * @param {Logger} logger */ -function processData(filename) { +const processData = filename => { let errors = []; let actual = fs.readFileSync(filename, 'utf-8').trim(); @@ -172,7 +172,7 @@ function processData(filename) { ); return errors; -} +}; /** * @param {Object[]} errors @@ -180,7 +180,7 @@ function processData(filename) { * @param {string|RegExp} regexp * @param {(match: RegExpExecArray) => Object} matchHandler */ -function processLink(errors, actual, regexp, matchHandler) { +const processLink = (errors, actual, regexp, matchHandler) => { const re = new RegExp(regexp, 'g'); /** @type {RegExpExecArray} */ let match; @@ -200,12 +200,12 @@ function processLink(errors, actual, regexp, matchHandler) { }); } } -} +}; /** * @param {string} filename */ -function testLinks(filename) { +const testLinks = filename => { /** @type {Object[]} */ let errors = processData(filename); @@ -223,6 +223,6 @@ function testLinks(filename) { return true; } return false; -} +}; module.exports = testLinks; diff --git a/test/linter/test-prefix.js b/test/linter/test-prefix.js index 542e3939060dec..458102a7610781 100644 --- a/test/linter/test-prefix.js +++ b/test/linter/test-prefix.js @@ -13,7 +13,7 @@ const chalk = require('chalk'); * @param {string} prefix * @param {string} [path] */ -function checkPrefix(data, category, errors, prefix, path = '') { +const checkPrefix = (data, category, errors, prefix, path = '') => { for (const key in data) { if (key === 'prefix' && typeof data[key] === 'string') { if (data[key].includes(prefix)) { @@ -34,14 +34,14 @@ function checkPrefix(data, category, errors, prefix, path = '') { } } return errors; -} +}; /** * @param {Identifier} data * @param {string} category * @return {string[]} */ -function processData(data, category) { +const processData = (data, category) => { let errors = []; let prefixes = []; @@ -56,12 +56,12 @@ function processData(data, category) { checkPrefix(data, category, errors, prefix); } return errors; -} +}; /** * @param {string} filename */ -function testPrefix(filename) { +const testPrefix = filename => { const relativePath = path.relative( path.resolve(__dirname, '..', '..'), filename, @@ -83,6 +83,6 @@ function testPrefix(filename) { return true; } return false; -} +}; module.exports = testPrefix; diff --git a/test/linter/test-real-values.js b/test/linter/test-real-values.js index 64c913a0e5f9b7..15042034e3461e 100644 --- a/test/linter/test-real-values.js +++ b/test/linter/test-real-values.js @@ -47,7 +47,7 @@ const blockList = { * @param {string} relPath * @param {Logger} logger */ -function checkRealValues(supportData, blockList, relPath, logger) { +const checkRealValues = (supportData, blockList, relPath, logger) => { for (const browser of blockList) { /** @type {SimpleSupportStatement[]} */ const supportStatements = []; @@ -76,12 +76,39 @@ function checkRealValues(supportData, blockList, relPath, logger) { } } } -} +}; + +/** + * @param {Identifier} data + * @param {string} [relPath] + */ +const findSupport = (data, category, logger, relPath) => { + for (const prop in data) { + if (prop === '__compat' && data[prop].support) { + if (blockList[category] && blockList[category].length > 0) + checkRealValues( + data[prop].support, + blockList[category], + relPath, + logger, + ); + } + const sub = data[prop]; + if (typeof sub === 'object') { + findSupport( + sub, + category, + logger, + relPath ? `${relPath}.${prop}` : `${prop}`, + ); + } + } +}; /** * @param {string} filename */ -function testRealValues(filename) { +const testRealValues = filename => { const relativePath = path.relative( path.resolve(__dirname, '..', '..'), filename, @@ -100,28 +127,7 @@ function testRealValues(filename) { }, }; - /** - * @param {Identifier} data - * @param {string} [relPath] - */ - function findSupport(data, relPath) { - for (const prop in data) { - if (prop === '__compat' && data[prop].support) { - if (blockList[category] && blockList[category].length > 0) - checkRealValues( - data[prop].support, - blockList[category], - relPath, - logger, - ); - } - const sub = data[prop]; - if (typeof sub === 'object') { - findSupport(sub, relPath ? `${relPath}.${prop}` : `${prop}`); - } - } - } - findSupport(data); + findSupport(data, category, logger); if (errors.length) { console.error( @@ -135,6 +141,6 @@ function testRealValues(filename) { return true; } return false; -} +}; module.exports = testRealValues; diff --git a/test/linter/test-schema.js b/test/linter/test-schema.js index 9cb809552b0c3d..9d8f2592473cd7 100644 --- a/test/linter/test-schema.js +++ b/test/linter/test-schema.js @@ -10,10 +10,10 @@ const ajv = new Ajv({ jsonPointers: true, allErrors: true }); * @param {string} dataFilename * @param {string} [schemaFilename] */ -function testSchema( +const testSchema = ( dataFilename, schemaFilename = './../../schemas/compat-data.schema.json', -) { +) => { const schema = require(schemaFilename); const data = require(dataFilename); @@ -33,6 +33,6 @@ function testSchema( return true; } return false; -} +}; module.exports = testSchema; diff --git a/test/linter/test-style.js b/test/linter/test-style.js index 5bddec3d9cdaf6..7a4f9691920303 100644 --- a/test/linter/test-style.js +++ b/test/linter/test-style.js @@ -17,7 +17,7 @@ const compareFeatures = require('../../scripts/compare-features'); * * @returns {*} The new value */ -function orderSupportBlock(key, value) { +const orderSupportBlock = (key, value) => { if (key === '__compat') { value.support = Object.keys(value.support) .sort() @@ -27,7 +27,7 @@ function orderSupportBlock(key, value) { }, {}); } return value; -} +}; /** * Return a new feature object whose first-level properties have been @@ -41,7 +41,7 @@ function orderSupportBlock(key, value) { * * @returns {*} The new value */ -function orderFeatures(key, value) { +const orderFeatures = (key, value) => { if (value instanceof Object && '__compat' in value) { value = Object.keys(value) .sort(compareFeatures) @@ -51,13 +51,13 @@ function orderFeatures(key, value) { }, {}); } return value; -} +}; /** * @param {string} filename * @param {import('../utils').Logger} logger */ -function processData(filename, logger) { +const processData = (filename, logger) => { let actual = fs.readFileSync(filename, 'utf-8').trim(); /** @type {import('../../types').CompatData} */ const dataObject = JSON.parse(actual); @@ -137,9 +137,9 @@ function processData(filename, logger) { ); } } -} +}; -function testStyle(filename) { +const testStyle = filename => { /** @type {string[]} */ const errors = []; const logger = { @@ -163,6 +163,6 @@ function testStyle(filename) { return true; } return false; -} +}; module.exports = testStyle; diff --git a/test/linter/test-versions.js b/test/linter/test-versions.js index 5a7a52c9817cf0..e58e0e54ec5c28 100644 --- a/test/linter/test-versions.js +++ b/test/linter/test-versions.js @@ -35,20 +35,20 @@ for (const browser of Object.keys(browsers)) { * @param {string} browserIdentifier * @param {VersionValue} version */ -function isValidVersion(browserIdentifier, version) { +const isValidVersion = (browserIdentifier, version) => { if (typeof version === 'string') { return validBrowserVersions[browserIdentifier].includes(version); } else { return true; } -} +}; /** * @param {SupportBlock} supportData * @param {string} relPath * @param {import('../utils').Logger} logger */ -function checkVersions(supportData, relPath, logger) { +const checkVersions = (supportData, relPath, logger) => { const browsersToCheck = Object.keys(supportData); for (const browser of browsersToCheck) { if (validBrowserVersions[browser]) { @@ -122,12 +122,28 @@ function checkVersions(supportData, relPath, logger) { } } } -} +}; + +/** + * @param {Identifier} data + * @param {string} [relPath] + */ +const findSupport = (data, logger, relPath) => { + for (const prop in data) { + if (prop === '__compat' && data[prop].support) { + checkVersions(data[prop].support, relPath, logger); + } + const sub = data[prop]; + if (typeof sub === 'object') { + findSupport(sub, logger, relPath ? `${relPath}.${prop}` : `${prop}`); + } + } +}; /** * @param {string} filename */ -function testVersions(filename) { +const testVersions = filename => { /** @type {Identifier} */ const data = require(filename); @@ -140,22 +156,7 @@ function testVersions(filename) { }, }; - /** - * @param {Identifier} data - * @param {string} [relPath] - */ - function findSupport(data, relPath) { - for (const prop in data) { - if (prop === '__compat' && data[prop].support) { - checkVersions(data[prop].support, relPath, logger); - } - const sub = data[prop]; - if (typeof sub === 'object') { - findSupport(sub, relPath ? `${relPath}.${prop}` : `${prop}`); - } - } - } - findSupport(data); + findSupport(data, logger); if (errors.length) { console.error( @@ -169,6 +170,6 @@ function testVersions(filename) { return true; } return false; -} +}; module.exports = testVersions; diff --git a/test/test-regexes.js b/test/test-regexes.js index 470b1abda0ef43..107a764c446284 100644 --- a/test/test-regexes.js +++ b/test/test-regexes.js @@ -16,18 +16,18 @@ const bcd = require('..'); /** * @param {string} dottedFeature */ -function lookup(dottedFeature) { +const lookup = dottedFeature => { const x = dottedFeature.split('.'); const feature = x.reduce((prev, current) => prev[current], bcd); return feature; -} +}; /** * @param {Identifier} feature * @param {string[]} matches * @param {string[]} misses */ -function testToken(feature, matches, misses) { +const testToken = (feature, matches, misses) => { const str = feature.__compat.matches.regex_token || feature.__compat.matches.regex_value; @@ -39,7 +39,7 @@ function testToken(feature, matches, misses) { misses.forEach(miss => assert.ok(!regexp.test(miss), `${regexp} erroneously matched ${miss}`), ); -} +}; /** @type {TestCase[]} */ const tests = [ diff --git a/test/test-utils.js b/test/test-utils.js index 8e5c072d7ae884..83699238dca85c 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -62,7 +62,7 @@ it('`escapeInvisibles()` works correctly', () => { * @param {string} message * @param {() => void | Promise} testCase */ -function it(message, testCase) { +const it = (message, testCase) => { const spinner = ora({ stream: process.stdout, text: message, @@ -101,4 +101,4 @@ function it(message, testCase) { return; } spinner.succeed(); -} +}; diff --git a/test/utils.js b/test/utils.js index fa561f0cc16487..3307310f2e40eb 100644 --- a/test/utils.js +++ b/test/utils.js @@ -32,13 +32,13 @@ const IS_WINDOWS = platform() === 'win32'; * * @param {string} str */ -function escapeInvisibles(str) { +const escapeInvisibles = str => { // This should now be O(n) instead of O(n*m), // where n = string length; m = invisible characters return INVISIBLES_REGEXP[Symbol.replace](str, char => { return INVISIBLES_MAP[char] || char; }); -} +}; /** * Gets the row and column matching the index in a string. @@ -47,7 +47,7 @@ function escapeInvisibles(str) { * @param {number} index * @return {[number, number] | [null, null]} */ -function indexToPosRaw(str, index) { +const indexToPosRaw = (str, index) => { let line = 1, col = 1; let prevChar = null; @@ -81,7 +81,7 @@ function indexToPosRaw(str, index) { } return [line, col]; -} +}; /** * Gets the row and column matching the index in a string and formats it. @@ -90,17 +90,17 @@ function indexToPosRaw(str, index) { * @param {number} index * @return {string} The line and column in the form of: `"(Ln , Col )"` */ -function indexToPos(str, index) { +const indexToPos = (str, index) => { const [line, col] = indexToPosRaw(str, index); return `(Ln ${line}, Col ${col})`; -} +}; /** * @param {string} actual * @param {string} expected * @return {string} */ -function jsonDiff(actual, expected) { +const jsonDiff = (actual, expected) => { const actualLines = actual.split(/\n/); const expectedLines = expected.split(/\n/); @@ -111,7 +111,7 @@ function jsonDiff(actual, expected) { {green Expected: {bold ${escapeInvisibles(expectedLines[i])}}}`; } } -} +}; module.exports = { INVISIBLES_MAP, From da4ba61d5f02da24d65da490d9a1115305d5a8d2 Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Sat, 28 Mar 2020 12:17:14 -0700 Subject: [PATCH 2/7] Move load functions to top level (and turn them into arrow functions) --- scripts/fix-browser-order.js | 46 +++++++++---------- scripts/fix-feature-order.js | 46 +++++++++---------- .../migrations/002-remove-webview-flags.js | 46 +++++++++---------- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/scripts/fix-browser-order.js b/scripts/fix-browser-order.js index c9475bbb70135b..7bdc4fc6eb09c6 100644 --- a/scripts/fix-browser-order.js +++ b/scripts/fix-browser-order.js @@ -53,36 +53,36 @@ const fixBrowserOrder = filename => { } }; -if (require.main === module) { - /** - * @param {string[]} files - */ - function load(...files) { - for (let file of files) { - if (file.indexOf(__dirname) !== 0) { - file = path.resolve(__dirname, '..', file); - } - - if (!fs.existsSync(file)) { - continue; // Ignore non-existent files - } +/** + * @param {string[]} files + */ +const load = (...files) => { + for (let file of files) { + if (file.indexOf(__dirname) !== 0) { + file = path.resolve(__dirname, '..', file); + } - if (fs.statSync(file).isFile()) { - if (path.extname(file) === '.json') { - fixBrowserOrder(file); - } + if (!fs.existsSync(file)) { + continue; // Ignore non-existent files + } - continue; + if (fs.statSync(file).isFile()) { + if (path.extname(file) === '.json') { + fixBrowserOrder(file); } - const subFiles = fs.readdirSync(file).map(subfile => { - return path.join(file, subfile); - }); - - load(...subFiles); + continue; } + + const subFiles = fs.readdirSync(file).map(subfile => { + return path.join(file, subfile); + }); + + load(...subFiles); } +}; +if (require.main === module) { if (process.argv[2]) { load(process.argv[2]); } else { diff --git a/scripts/fix-feature-order.js b/scripts/fix-feature-order.js index 543e9a74127dfb..7cea3d4e97548b 100644 --- a/scripts/fix-feature-order.js +++ b/scripts/fix-feature-order.js @@ -55,36 +55,36 @@ const fixFeatureOrder = filename => { } }; -if (require.main === module) { - /** - * @param {string[]} files - */ - function load(...files) { - for (let file of files) { - if (file.indexOf(__dirname) !== 0) { - file = path.resolve(__dirname, '..', file); - } - - if (!fs.existsSync(file)) { - continue; // Ignore non-existent files - } +/** + * @param {string[]} files + */ +const load = (...files) => { + for (let file of files) { + if (file.indexOf(__dirname) !== 0) { + file = path.resolve(__dirname, '..', file); + } - if (fs.statSync(file).isFile()) { - if (path.extname(file) === '.json') { - fixFeatureOrder(file); - } + if (!fs.existsSync(file)) { + continue; // Ignore non-existent files + } - continue; + if (fs.statSync(file).isFile()) { + if (path.extname(file) === '.json') { + fixFeatureOrder(file); } - const subFiles = fs.readdirSync(file).map(subfile => { - return path.join(file, subfile); - }); - - load(...subFiles); + continue; } + + const subFiles = fs.readdirSync(file).map(subfile => { + return path.join(file, subfile); + }); + + load(...subFiles); } +}; +if (require.main === module) { if (process.argv[2]) { load(process.argv[2]); } else { diff --git a/scripts/migrations/002-remove-webview-flags.js b/scripts/migrations/002-remove-webview-flags.js index 1f8c362b876008..e282f432fac40f 100644 --- a/scripts/migrations/002-remove-webview-flags.js +++ b/scripts/migrations/002-remove-webview-flags.js @@ -58,36 +58,36 @@ const fixWebViewFlags = filename => { } }; -if (require.main === module) { - /** - * @param {string[]} files - */ - function load(...files) { - for (let file of files) { - if (file.indexOf(__dirname) !== 0) { - file = path.resolve(__dirname, '..', '..', file); - } - - if (!fs.existsSync(file)) { - continue; // Ignore non-existent files - } +/** + * @param {string[]} files + */ +const load = (...files) => { + for (let file of files) { + if (file.indexOf(__dirname) !== 0) { + file = path.resolve(__dirname, '..', '..', file); + } - if (fs.statSync(file).isFile()) { - if (path.extname(file) === '.json') { - fixWebViewFlags(file); - } + if (!fs.existsSync(file)) { + continue; // Ignore non-existent files + } - continue; + if (fs.statSync(file).isFile()) { + if (path.extname(file) === '.json') { + fixWebViewFlags(file); } - const subFiles = fs.readdirSync(file).map(subfile => { - return path.join(file, subfile); - }); - - load(...subFiles); + continue; } + + const subFiles = fs.readdirSync(file).map(subfile => { + return path.join(file, subfile); + }); + + load(...subFiles); } +}; +if (require.main === module) { if (process.argv[2]) { load(process.argv[2]); } else { From 0b7d016efe91765d2d1d24b603c8d57f4503742f Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Tue, 31 Mar 2020 05:02:08 -0700 Subject: [PATCH 3/7] Move functions back out of top level for now --- test/linter/test-browsers.js | 9 +++--- test/linter/test-real-values.js | 54 ++++++++++++++++----------------- test/linter/test-versions.js | 32 +++++++++---------- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/test/linter/test-browsers.js b/test/linter/test-browsers.js index 46d9553dd72b3c..a990824275ec32 100644 --- a/test/linter/test-browsers.js +++ b/test/linter/test-browsers.js @@ -26,11 +26,6 @@ const browsers = { 'webextensions-mobile': ['firefox_android'], }; -const hasVersionAddedOnly = statement => { - const keys = Object.keys(statement); - return keys.length === 1 && keys[0] === 'version_added'; -}; - /** * @param {Identifier} data * @param {string[]} displayBrowsers @@ -77,6 +72,10 @@ const processData = ( const statementList = Array.isArray(supportStatement) ? supportStatement : [supportStatement]; + const hasVersionAddedOnly = statement => { + const keys = Object.keys(statement); + return keys.length === 1 && keys[0] === 'version_added'; + }; let sawVersionAddedOnly = false; for (const statement of statementList) { if (hasVersionAddedOnly(statement)) { diff --git a/test/linter/test-real-values.js b/test/linter/test-real-values.js index 15042034e3461e..2ad48901831d38 100644 --- a/test/linter/test-real-values.js +++ b/test/linter/test-real-values.js @@ -78,33 +78,6 @@ const checkRealValues = (supportData, blockList, relPath, logger) => { } }; -/** - * @param {Identifier} data - * @param {string} [relPath] - */ -const findSupport = (data, category, logger, relPath) => { - for (const prop in data) { - if (prop === '__compat' && data[prop].support) { - if (blockList[category] && blockList[category].length > 0) - checkRealValues( - data[prop].support, - blockList[category], - relPath, - logger, - ); - } - const sub = data[prop]; - if (typeof sub === 'object') { - findSupport( - sub, - category, - logger, - relPath ? `${relPath}.${prop}` : `${prop}`, - ); - } - } -}; - /** * @param {string} filename */ @@ -127,6 +100,33 @@ const testRealValues = filename => { }, }; + /** + * @param {Identifier} data + * @param {string} [relPath] + */ + const findSupport = (data, category, logger, relPath) => { + for (const prop in data) { + if (prop === '__compat' && data[prop].support) { + if (blockList[category] && blockList[category].length > 0) + checkRealValues( + data[prop].support, + blockList[category], + relPath, + logger, + ); + } + const sub = data[prop]; + if (typeof sub === 'object') { + findSupport( + sub, + category, + logger, + relPath ? `${relPath}.${prop}` : `${prop}`, + ); + } + } + }; + findSupport(data, category, logger); if (errors.length) { diff --git a/test/linter/test-versions.js b/test/linter/test-versions.js index e58e0e54ec5c28..be3cb21bad1d5f 100644 --- a/test/linter/test-versions.js +++ b/test/linter/test-versions.js @@ -124,22 +124,6 @@ const checkVersions = (supportData, relPath, logger) => { } }; -/** - * @param {Identifier} data - * @param {string} [relPath] - */ -const findSupport = (data, logger, relPath) => { - for (const prop in data) { - if (prop === '__compat' && data[prop].support) { - checkVersions(data[prop].support, relPath, logger); - } - const sub = data[prop]; - if (typeof sub === 'object') { - findSupport(sub, logger, relPath ? `${relPath}.${prop}` : `${prop}`); - } - } -}; - /** * @param {string} filename */ @@ -156,6 +140,22 @@ const testVersions = filename => { }, }; + /** + * @param {Identifier} data + * @param {string} [relPath] + */ + const findSupport = (data, logger, relPath) => { + for (const prop in data) { + if (prop === '__compat' && data[prop].support) { + checkVersions(data[prop].support, relPath, logger); + } + const sub = data[prop]; + if (typeof sub === 'object') { + findSupport(sub, logger, relPath ? `${relPath}.${prop}` : `${prop}`); + } + } + }; + findSupport(data, logger); if (errors.length) { From 5a5fbd7cae8e6bb6e84da74948791a3e11b640f5 Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Tue, 5 May 2020 21:30:45 -0700 Subject: [PATCH 4/7] Add missing require() --- test/linter/test-style.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/linter/test-style.js b/test/linter/test-style.js index d25b37764b2d62..9198f9b06da7f0 100644 --- a/test/linter/test-style.js +++ b/test/linter/test-style.js @@ -1,6 +1,7 @@ 'use strict'; const fs = require('fs'); const chalk = require('chalk'); +const url = require('url'); const { IS_WINDOWS, indexToPos, jsonDiff } = require('../utils.js'); const compareFeatures = require('../../scripts/compare-features'); From 779c0501421a429a78c52db3f9514b7759ac26c6 Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Tue, 5 May 2020 21:30:45 -0700 Subject: [PATCH 5/7] Revert "Add missing require()" This reverts commit 5a5fbd7cae8e6bb6e84da74948791a3e11b640f5. --- test/linter/test-style.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/linter/test-style.js b/test/linter/test-style.js index 9198f9b06da7f0..d25b37764b2d62 100644 --- a/test/linter/test-style.js +++ b/test/linter/test-style.js @@ -1,7 +1,6 @@ 'use strict'; const fs = require('fs'); const chalk = require('chalk'); -const url = require('url'); const { IS_WINDOWS, indexToPos, jsonDiff } = require('../utils.js'); const compareFeatures = require('../../scripts/compare-features'); From 1a94c490fde7e2e9ae558bd26bf18b655cb03f11 Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Mon, 11 May 2020 23:31:28 -0700 Subject: [PATCH 6/7] Remove accidentally-added code --- test/linter/test-style.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/test/linter/test-style.js b/test/linter/test-style.js index d25b37764b2d62..c4c854a674bcf5 100644 --- a/test/linter/test-style.js +++ b/test/linter/test-style.js @@ -103,25 +103,6 @@ const processData = (filename, logger) => { )} - Found {yellow \\"}, but expected {green \'} for .}`, ); } - - const regexp = new RegExp( - String.raw`]+)'>((?:.(?!))*.)`, - 'g', - ); - const match = regexp.exec(actual); - if (match) { - const a_url = url.parse(match[1]); - if (a_url.hostname === null) { - logger.error( - chalk`{red → ${indexToPos( - actual, - constructorMatch.index, - )} - Include hostname in URL ({yellow ${ - match[1] - }} → {green {bold https://developer.mozilla.org/}${match[1]}}).}`, - ); - } - } }; const testStyle = filename => { From a90cb7854060eb3f73e74b73a7c8669a385b14fb Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Thu, 8 Oct 2020 15:37:32 -0700 Subject: [PATCH 7/7] Fix Prettier issues --- test/linter/test-browsers.js | 2 +- test/linter/test-real-values.js | 2 +- test/linter/test-style.js | 2 +- test/linter/test-versions.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/linter/test-browsers.js b/test/linter/test-browsers.js index a98a40aafaf39f..d5e052f537147b 100644 --- a/test/linter/test-browsers.js +++ b/test/linter/test-browsers.js @@ -148,6 +148,6 @@ const testBrowsers = filename => { logger.emit(); return logger.hasErrors(); -} +}; module.exports = testBrowsers; diff --git a/test/linter/test-real-values.js b/test/linter/test-real-values.js index b5d333336c519c..3b1eed98a9650a 100644 --- a/test/linter/test-real-values.js +++ b/test/linter/test-real-values.js @@ -123,6 +123,6 @@ const testRealValues = filename => { logger.emit(); return logger.hasErrors(); -} +}; module.exports = testRealValues; diff --git a/test/linter/test-style.js b/test/linter/test-style.js index 28c608cc379da7..c8cb96e7cb28f9 100644 --- a/test/linter/test-style.js +++ b/test/linter/test-style.js @@ -113,6 +113,6 @@ const testStyle = filename => { logger.emit(); return logger.hasErrors(); -} +}; module.exports = testStyle; diff --git a/test/linter/test-versions.js b/test/linter/test-versions.js index 01237df413400a..b4c4f79d7d1a17 100644 --- a/test/linter/test-versions.js +++ b/test/linter/test-versions.js @@ -154,6 +154,6 @@ const testVersions = filename => { logger.emit(); return logger.hasErrors(); -} +}; module.exports = testVersions;