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: convert all functions to arrow functions #5894

Closed
46 changes: 23 additions & 23 deletions scripts/fix-browser-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
50 changes: 25 additions & 25 deletions scripts/fix-feature-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,7 +35,7 @@ function orderFeatures(key, value) {
}, {});
}
return value;
}
};

/**
* @param {Promise<void>} filename
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions scripts/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,7 +34,7 @@ function load(...files) {

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

if (process.argv[2]) {
load(process.argv[2]);
Expand Down
46 changes: 23 additions & 23 deletions scripts/migrations/002-remove-webview-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions scripts/mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -690,7 +690,7 @@ function mirrorDataByFile(browser, filepath, source, modify) {
}

return true;
}
};

/**
* Allows mirroring by feature ID (e.g. "html.elements.a")
Expand Down
4 changes: 2 additions & 2 deletions scripts/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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) {
Expand Down Expand Up @@ -61,7 +61,7 @@ function traverseFeatures(obj, depth, identifier) {
}
}
}
}
};

let features = [];
const folders =
Expand Down
4 changes: 2 additions & 2 deletions test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -139,7 +139,7 @@ function load(...files) {

return load(...subFiles) || prevHasErrors;
}, false);
}
};

/** @type {boolean} */
var hasErrors = argv.files
Expand Down
14 changes: 7 additions & 7 deletions test/linter/test-browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,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;

Expand Down Expand Up @@ -72,10 +72,10 @@ function processData(
const statementList = Array.isArray(supportStatement)
? supportStatement
: [supportStatement];
function hasVersionAddedOnly(statement) {
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)) {
Expand Down Expand Up @@ -103,13 +103,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,
Expand Down Expand Up @@ -148,6 +148,6 @@ function testBrowsers(filename) {

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

module.exports = testBrowsers;
4 changes: 2 additions & 2 deletions test/linter/test-consistency.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class ConsistencyChecker {
/**
* @param {string} filename
*/
function testConsistency(filename) {
const testConsistency = filename => {
/** @type {Identifier} */
let data = require(filename);

Expand Down Expand Up @@ -398,6 +398,6 @@ function testConsistency(filename) {
return true;
}
return false;
}
};

module.exports = testConsistency;
12 changes: 6 additions & 6 deletions test/linter/test-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { IS_WINDOWS, indexToPos, indexToPosRaw } = require('../utils.js');
/**
* @param {string} filename
*/
function processData(filename) {
const processData = filename => {
let errors = [];

let actual = fs.readFileSync(filename, 'utf-8').trim();
Expand Down Expand Up @@ -183,15 +183,15 @@ function processData(filename) {
);

return errors;
}
};

/**
* @param {Object[]} errors
* @param {string} actual
* @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;
Expand All @@ -211,12 +211,12 @@ function processLink(errors, actual, regexp, matchHandler) {
});
}
}
}
};

/**
* @param {string} filename
*/
function testLinks(filename) {
const testLinks = filename => {
/** @type {Object[]} */
let errors = processData(filename);

Expand All @@ -234,6 +234,6 @@ function testLinks(filename) {
return true;
}
return false;
}
};

module.exports = testLinks;
Loading