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

Refactor: executable script consistency #5890

Merged
merged 23 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f2af1c2
Refactor: only include env on executable scripts and use strict on all
queengooborg Mar 27, 2020
6dc2381
Make all executables importable
queengooborg Mar 27, 2020
948076f
Merge branch 'master' into refactor/shbang-and-use-strict
queengooborg Aug 20, 2020
233c09b
Merge branch 'master' into refactor/shbang-and-use-strict
queengooborg Oct 31, 2020
bf57e3a
Merge branch 'master' into refactor/shbang-and-use-strict
queengooborg Nov 13, 2020
843e200
Merge branch 'master' into refactor/shbang-and-use-strict
queengooborg Feb 13, 2021
4702ac0
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 15, 2021
c1dffd0
Update new scripts
queengooborg Apr 15, 2021
ef5684a
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Sep 24, 2021
56856e0
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 18, 2022
e81017a
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 19, 2022
17eabb5
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 19, 2022
387c6fe
Update all script files
queengooborg Apr 19, 2022
8612d0c
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 19, 2022
76de15c
Fix files within index
queengooborg Apr 19, 2022
8ae9314
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 20, 2022
7f4da8a
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 22, 2022
e098f68
Fix formatting
queengooborg Apr 22, 2022
e687059
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg Apr 26, 2022
4178c4f
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg May 8, 2022
29289f9
Merge branch 'main' into refactor/shbang-and-use-strict
queengooborg May 13, 2022
83ff421
Undo unrelated changes
queengooborg May 13, 2022
86330a3
Remove obsolete function call
queengooborg May 13, 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
36 changes: 21 additions & 15 deletions scripts/fix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@ function load(...files) {
}
}

if (process.argv[2]) {
load(process.argv[2]);
} else {
load(
'api',
'css',
'html',
'http',
'svg',
'javascript',
'mathml',
'test',
'webdriver',
'webextensions',
);
if (require.main === module) {
if (process.argv[2]) {
load(process.argv[2]);
} else {
load(
'api',
'css',
'html',
'http',
'svg',
'javascript',
'mathml',
'test',
'webdriver',
'webextensions',
);

format();
}
}

module.exports = load;
4 changes: 3 additions & 1 deletion scripts/release/pulls.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ function main() {
}
}

main();
if (require.main === module) {
main();
}
4 changes: 3 additions & 1 deletion scripts/release/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ async function main() {
);
}

main();
if (require.main === module) {
main();
}
39 changes: 27 additions & 12 deletions scripts/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,32 @@ function traverseFeatures(obj, depth, identifier) {
}
}

let features = [];
const folders =
argv.folder == 'all'
? ['api', 'css', 'html', 'http', 'svg', 'javascript', 'mathml', 'webdriver']
: argv.folder.split(',');
const values = Array.isArray(argv.value)
? argv.value
: argv.value.toString().split(',');
const main = (folder = 'all', value = ['null', 'true'], depth = 100) => {
let features = [];
const folders =
folder == 'all'
? [
'api',
'css',
'html',
'http',
'svg',
'javascript',
'mathml',
'webdriver',
]
: folder.split(',');
const values = Array.isArray(value) ? value : value.toString().split(',');

for (const folder in folders)
traverseFeatures(bcd[folders[folder]], argv.depth, `${folders[folder]}.`);
for (const folder in folders)
traverseFeatures(bcd[folders[folder]], depth, `${folders[folder]}.`);

console.log(features.join('\n'));
console.log(features.length);
console.log(features.join('\n'));
console.log(features.length);
};

if (require.main === module) {
main(argv.folder, argv.value, argv.depth);
}

module.exports = main;
92 changes: 51 additions & 41 deletions test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,49 +150,59 @@ function load(...files) {
}, false);
}

/** @type {boolean} */
var hasErrors = argv.files
? load.apply(undefined, argv.files)
: load(
'api',
'browsers',
'css',
'html',
'http',
'svg',
'javascript',
'mathml',
'webdriver',
'webextensions',
const main = (files) => {
/** @type {boolean} */
var hasErrors = argv.files
? load.apply(undefined, argv.files)
: load(
'api',
'browsers',
'css',
'html',
'http',
'svg',
'javascript',
'mathml',
'webdriver',
'webextensions',
);

if (hasErrors) {
console.warn('');
console.warn(
chalk`{red Problems in ${pluralize('file', filesWithErrors.size)}:}`,
);

if (hasErrors) {
console.warn('');
console.warn(
chalk`{red Problems in ${pluralize('file', filesWithErrors.size)}:}`,
);
for (const [fileName, file] of filesWithErrors) {
console.warn(chalk`{red.bold ✖ ${fileName}}`);
try {
if (file.indexOf('browsers' + path.sep) !== -1) {
testSchema(file, './../../schemas/browsers.schema.json');
testBrowsersData(file);
testLinks(file);
} else {
testSchema(file);
testStyle(file);
testLinks(file);
testVersions(file);
testRealValues(file);
testBrowsersPresence(file);
testConsistency(file);
testPrefix(file);
testDescriptions(file);
testNotes(file);
for (const [fileName, file] of filesWithErrors) {
console.warn(chalk`{red.bold ✖ ${fileName}}`);
try {
if (file.indexOf('browsers' + path.sep) !== -1) {
testSchema(file, './../../schemas/browsers.schema.json');
testBrowsersData(file);
testLinks(file);
} else {
testSchema(file);
testStyle(file);
testLinks(file);
testVersions(file);
testRealValues(file);
testBrowsersPresence(file);
testConsistency(file);
testPrefix(file);
testDescriptions(file);
testNotes(file);
}
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
}
return true;
}
process.exit(1);

return false;
};

if (require.main === module) {
process.exit(main(argv.files) ? 1 : 0);
}

module.exports = main;
52 changes: 28 additions & 24 deletions test/test-regexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ const assert = require('assert').strict;
/** @type {Identifier} */
const bcd = require('..');

/** @type {TestCase[]} */
const tests = [
{
features: ['css.properties.color.alpha_hexadecimal_notation'],
matches: ['#003399ff', '#0af9'],
misses: ['#00aaff', '#0af', 'green', '#greenish'],
},
{
features: ['css.properties.transform-origin.three_value_syntax'],
matches: [
'2px 30% 10px', // length, percentage, length
'right bottom -2cm', // two keywords and length
'calc(50px - 25%) 2px 1px', // lengths with calc
],
misses: [
'center', // one value syntax
'left 5px', // two value syntax
'left calc(10px - 50%)', // two value syntax with calc
],
},
];

/**
* @param {string} dottedFeature
*/
Expand Down Expand Up @@ -45,28 +67,10 @@ function testToken(feature, matches, misses) {
);
}

/** @type {TestCase[]} */
const tests = [
{
features: ['css.properties.color.alpha_hexadecimal_notation'],
matches: ['#003399ff', '#0af9'],
misses: ['#00aaff', '#0af', 'green', '#greenish'],
},
{
features: ['css.properties.transform-origin.three_value_syntax'],
matches: [
'2px 30% 10px', // length, percentage, length
'right bottom -2cm', // two keywords and length
'calc(50px - 25%) 2px 1px', // lengths with calc
],
misses: [
'center', // one value syntax
'left 5px', // two value syntax
'left calc(10px - 50%)', // two value syntax with calc
],
},
];
const testRegexes = () => {
tests.forEach(({ features, matches, misses }) => {
features.forEach((feature) => testToken(lookup(feature), matches, misses));
});
};

tests.forEach(({ features, matches, misses }) => {
features.forEach((feature) => testToken(lookup(feature), matches, misses));
});
module.exports = testRegexes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this script not have an if (require.main === module) { block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script isn't supposed to be run on its own, but rather as a Mocha unittest. It was never actually hooked up though, and I'm not too worried about hooking it up now since it's going to be removed in #15781!