Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -2,14 +2,13 @@ const fse = require('fs-extra');
const path = require('path');
const generateInfo = require('./generate-info');
/**
* Read the symbols from info file.
* @return {Promise<Array>} Resolves with an array of symbol objects.
*/
async function getSymbols() {
const info = await generateInfo();
return info.symbols.filter(symbol => symbol.kind != 'member');
return info.symbols.filter((symbol) => symbol.kind != 'member');
}
/**
@@ -32,7 +31,6 @@ function getImport(symbol, member) {
}
}
/**
* Generate code to export a named symbol.
* @param {Object} symbol Symbol.
@@ -46,20 +44,20 @@ function formatSymbolExport(symbol, namespaces, imports) {
const isNamed = parts[0].indexOf('.') !== -1;
const nsParts = parts[0].replace(/^module\:/, '').split(/[\/\.]/);
const last = nsParts.length - 1;
const importName = isNamed ?
'_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last] :
'$' + nsParts.join('$');
const importName = isNamed
? '_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last]
: '$' + nsParts.join('$');
let line = nsParts[0];
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
line += `.${nsParts[i]}`;
namespaces[line] = (line in namespaces ? namespaces[line] : true) && i < ii - 1;
namespaces[line] =
(line in namespaces ? namespaces[line] : true) && i < ii - 1;
}
line += ` = ${importName};`;
imports[getImport(symbol, nsParts.pop())] = true;
return line;
}
/**
* Generate export code given a list symbol names.
* @param {Array<Object>} symbols List of symbols.
@@ -71,7 +69,7 @@ function generateExports(symbols) {
const namespaces = {};
const imports = [];
let blocks = [];
symbols.forEach(function(symbol) {
symbols.forEach(function (symbol) {
const name = symbol.name;
if (name.indexOf('#') == -1) {
const imp = getImport(symbol);
@@ -91,12 +89,13 @@ function generateExports(symbols) {
nsdefs.push(`${ns[i]} = {};`);
}
}
blocks = Object.keys(imports).concat('\nvar ol = {};\n', nsdefs.sort()).concat(blocks.sort());
blocks = Object.keys(imports)
.concat('\nvar ol = {};\n', nsdefs.sort())
.concat(blocks.sort());
blocks.push('', 'export default ol;');
return blocks.join('\n');
}
/**
* Generate the exports code.
* @return {Promise<string>} Resolves with the exports code.
@@ -106,21 +105,21 @@ async function main() {
return generateExports(symbols);
}
/**
* If running this module directly, read the config file, call the main
* function, and write the output file.
*/
if (require.main === module) {
main().then(async code => {
const filepath = path.join(__dirname, '..', 'build', 'index.js');
await fse.outputFile(filepath, code);
}).catch(err => {
process.stderr.write(`${err.message}\n`, () => process.exit(1));
});
main()
.then(async (code) => {
const filepath = path.join(__dirname, '..', 'build', 'index.js');
await fse.outputFile(filepath, code);
})
.catch((err) => {
process.stderr.write(`${err.message}\n`, () => process.exit(1));
});
}
/**
* Export main function.
*/

View File

@@ -20,7 +20,9 @@ function getBinaryPath(binaryName) {
const jsdocResolved = require.resolve('jsdoc/jsdoc.js');
const expectedPaths = [
path.join(__dirname, '..', 'node_modules', '.bin', binaryName),
path.resolve(path.join(path.dirname(jsdocResolved), '..', '.bin', binaryName))
path.resolve(
path.join(path.dirname(jsdocResolved), '..', '.bin', binaryName)
),
];
for (let i = 0; i < expectedPaths.length; i++) {
@@ -30,14 +32,21 @@ function getBinaryPath(binaryName) {
}
}
throw Error('JsDoc binary was not found in any of the expected paths: ' + expectedPaths);
throw Error(
'JsDoc binary was not found in any of the expected paths: ' + expectedPaths
);
}
const jsdoc = getBinaryPath('jsdoc');
const jsdocConfig = path.join(
__dirname, '..', 'config', 'jsdoc', 'info', 'conf.json');
__dirname,
'..',
'config',
'jsdoc',
'info',
'conf.json'
);
/**
* Generate a list of all .js paths in the source directory.
@@ -75,7 +84,6 @@ function getPaths() {
});
}
/**
* Parse the JSDoc output.
* @param {string} output JSDoc output
@@ -102,7 +110,6 @@ function parseOutput(output) {
return info;
}
/**
* Spawn JSDoc.
* @param {Array<string>} paths Paths to source files.
@@ -116,15 +123,15 @@ function spawnJSDoc(paths) {
const cwd = path.join(__dirname, '..');
const child = spawn(jsdoc, ['-c', jsdocConfig].concat(paths), {cwd: cwd});
child.stdout.on('data', data => {
child.stdout.on('data', (data) => {
output += String(data);
});
child.stderr.on('data', data => {
child.stderr.on('data', (data) => {
errors += String(data);
});
child.on('exit', code => {
child.on('exit', (code) => {
if (code) {
reject(new Error(errors || 'JSDoc failed with no output'));
return;
@@ -160,17 +167,17 @@ async function main() {
return await spawnJSDoc(paths);
}
/**
* If running this module directly, generate and write out the info.json file.
*/
if (require.main === module) {
main().then(write).catch(err => {
process.stderr.write(`${err.message}\n`, () => process.exit(1));
});
main()
.then(write)
.catch((err) => {
process.stderr.write(`${err.message}\n`, () => process.exit(1));
});
}
/**
* Export main function.
*/

View File

@@ -7,7 +7,9 @@ const buildDir = path.resolve(__dirname, '../build/ol');
// update the version number in util.js
const utilPath = path.join(buildDir, 'util.js');
const versionRegEx = /var VERSION = '(.*)';/g;
const utilSrc = fs.readFileSync(utilPath, 'utf-8').replace(versionRegEx, `var VERSION = '${pkg.version}';`);
const utilSrc = fs
.readFileSync(utilPath, 'utf-8')
.replace(versionRegEx, `var VERSION = '${pkg.version}';`);
fs.writeFileSync(utilPath, utilSrc, 'utf-8');
// write out simplified package.json
@@ -16,4 +18,8 @@ delete pkg.devDependencies;
delete pkg.style;
delete pkg.eslintConfig;
delete pkg.private;
fs.writeFileSync(path.join(buildDir, 'package.json'), JSON.stringify(pkg, null, 2), 'utf-8');
fs.writeFileSync(
path.join(buildDir, 'package.json'),
JSON.stringify(pkg, null, 2),
'utf-8'
);

View File

@@ -15,7 +15,7 @@ async function build(input, {minify = true} = {}) {
return null;
}
return code.replace('export let create;', '');
}
},
},
common(),
resolve(),
@@ -26,11 +26,11 @@ async function build(input, {minify = true} = {}) {
'@babel/preset-env',
{
'modules': false,
'targets': 'last 2 version, not dead'
}
]
]
})
'targets': 'last 2 version, not dead',
},
],
],
}),
];
if (minify) {
@@ -48,7 +48,7 @@ async function build(input, {minify = true} = {}) {
return new Worker(url);
}
`;
}
},
});
const bundle = await rollup.rollup({input, plugins});
@@ -68,7 +68,6 @@ async function build(input, {minify = true} = {}) {
exports.build = build;
/**
* Creates modules with inlined versions of the worker sources. These modules
* export a `create` function for creating a worker.
@@ -91,7 +90,7 @@ async function main() {
}
if (require.main === module) {
main().catch(err => {
main().catch((err) => {
process.stderr.write(`${err.stack}\n`);
process.exit(1);
});