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

Fix ESLint errors + JSDoc comments for scripts/ #5654

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 3 additions & 3 deletions scripts/compare-features.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

'use strict';

/**
*
* Sort a list of features based upon a specific order:
* 1. __compat is always first
* 2. Alphanumerical features starting with an uppercase letter (without symbols aside from - or _)
* 3. Alphanumerical features starting with a lowercase letter (without symbols aside from - or _)
* 4. All other features
*
* @param {string} a The name of the first object to perform comparison with
* @param {string} b The name of the second object to perform comparison with
* @returns {boolean} Result of localeCompare
*/

const compareFeatures = (a, b) => {
if (a == '__compat') return -1;
if (b == '__compat') return 1;
Expand Down
83 changes: 45 additions & 38 deletions scripts/fix-browser-order.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#!/usr/bin/env node
queengooborg marked this conversation as resolved.
Show resolved Hide resolved
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

/**
* Return a new "support_block" object whose first-level properties
* (browser names) have been ordered according to Array.prototype.sort,
* and so will be stringified in that order as well. This relies on
* guaranteed "own" property ordering, which is insertion order for
* non-integer keys (which is our case).
*
* @param {string} key The key in the object
* @param {*} value The value of the key
*
* @returns {*} The new value
*/

'use strict';
const fs = require('fs');
const path = require('path');
const { platform } = require('os');

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

/** Determines if the OS is Windows */
const IS_WINDOWS = platform() === 'win32';

/**
* Return a new "support_block" object whose first-level properties
* (browser names) have been ordered according to Array.prototype.sort,
* and so will be stringified in that order as well. This relies on
* guaranteed "own" property ordering, which is insertion order for
* non-integer keys (which is our case).
*
* @param {string} key The key of the object
* @param {Identifier} value The value of the key
* @returns {Identifier} Value with sorting applied
*/
const orderSupportBlock = (key, value) => {
if (key === '__compat') {
value.support = Object.keys(value.support)
Expand All @@ -36,7 +37,10 @@ const orderSupportBlock = (key, value) => {
};

/**
* @param {Promise<void>} filename
* Perform a fix of the browser order of a __compat.support block within all the data in a specified file. The function will then automatically write any needed changes back into the file.
*
* @param {string} filename The filename to perform fix upon
* @returns {void}
*/
const fixBrowserOrder = filename => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
Expand All @@ -53,36 +57,39 @@ 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
}
/**
* Recursively load one or more files and/or directories passed as arguments and perform browser sorting.
*
* @param {string[]} files The files to load and perform fix upon
* @returns {void}
*/
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 {
Expand Down
89 changes: 48 additions & 41 deletions scripts/fix-feature-order.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#!/usr/bin/env node
queengooborg marked this conversation as resolved.
Show resolved Hide resolved
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

'use strict';
const fs = require('fs');
const path = require('path');
const { platform } = require('os');

const compareFeatures = require('./compare-features');

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

/** Determines if the OS is Windows */
const IS_WINDOWS = platform() === 'win32';

/**
* Return a new feature object whose first-level properties have been
* ordered according to Array.prototype.sort, and so will be
Expand All @@ -10,22 +23,10 @@
* (which is our case).
*
* @param {string} key The key in the object
* @param {*} value The value of the key
*
* @returns {*} The new value
* @param {Identifier} value The value of the key
* @returns {Identifier} The new value
*/

'use strict';
const fs = require('fs');
const path = require('path');
const { platform } = require('os');

/** Determines if the OS is Windows */
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)
Expand All @@ -35,10 +36,13 @@ function orderFeatures(key, value) {
}, {});
}
return value;
}
};

/**
* @param {Promise<void>} filename
* Perform a fix of feature order within all the data in a specified file. The function will then automatically write any needed changes back into the file.
*
* @param {string} filename The filename to perform fix upon
* @returns {void}
*/
const fixFeatureOrder = filename => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
Expand All @@ -55,36 +59,39 @@ 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
}
/**
* Recursively load one or more files and/or directories passed as arguments and perform feature sorting.
*
* @param {string[]} files The files to load and perform fix upon
* @returns {void}
*/
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 {
Expand Down
1 change: 0 additions & 1 deletion scripts/fix-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

Expand Down
13 changes: 10 additions & 3 deletions scripts/fix.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

'use strict';
const fs = require('fs');
const path = require('path');
Expand All @@ -6,9 +10,12 @@ const fixFeatureOrder = require('./fix-feature-order');
const format = require('./fix-format');

/**
* @param {string[]} files
* Recursively load one or more files and/or directories passed as arguments and perform automatic fixes.
*
* @param {string[]} files The files to load and perform fix upon
* @returns {void}
*/
function load(...files) {
const load = (...files) => {
for (let file of files) {
if (file.indexOf(__dirname) !== 0) {
file = path.resolve(__dirname, '..', file);
Expand All @@ -34,7 +41,7 @@ function load(...files) {

load(...subFiles);
}
}
};

if (process.argv[2]) {
load(process.argv[2]);
Expand Down
Loading