summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-14 22:26:29 -0500
committerGitHub <noreply@github.com>2024-02-15 03:26:29 +0000
commit6bf7b0055765c4f2011c9614753d6714dc09be65 (patch)
tree0e782ae66556eaa61a34d9f32d77c831b2443ce5 /dev
parent7a4096240ce4faf70a785d047945388baa0daab3 (diff)
Eslint rule updates (#673)
* Install unicorn * Add rules * Fix issues * Install sonarjs * Set up rules * Fix issues * Install eslint-plugin-import and fix import extensions * Simplify permitted error names
Diffstat (limited to 'dev')
-rw-r--r--dev/bin/build.js10
-rw-r--r--dev/build-libs.js1
-rw-r--r--dev/data-error.js8
-rw-r--r--dev/generate-css-json.js10
-rw-r--r--dev/lib/dexie.js5
-rw-r--r--dev/schema-validate.js3
-rw-r--r--dev/util.js6
7 files changed, 19 insertions, 24 deletions
diff --git a/dev/bin/build.js b/dev/bin/build.js
index bc0a8cb8..e22159d6 100644
--- a/dev/bin/build.js
+++ b/dev/bin/build.js
@@ -195,12 +195,10 @@ async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath,
await createZip(extDir, excludeFiles, fullFileName, sevenZipExes, onUpdate, dryRun);
}
- if (!dryRun) {
- if (Array.isArray(fileCopies)) {
- for (const fileName2 of fileCopies) {
- const fileName2Safe = path.basename(fileName2);
- fs.copyFileSync(fullFileName, path.join(buildDir, fileName2Safe));
- }
+ if (!dryRun && Array.isArray(fileCopies)) {
+ for (const fileName2 of fileCopies) {
+ const fileName2Safe = path.basename(fileName2);
+ fs.copyFileSync(fullFileName, path.join(buildDir, fileName2Safe));
}
}
}
diff --git a/dev/build-libs.js b/dev/build-libs.js
index 15ab3c8d..f1570fad 100644
--- a/dev/build-libs.js
+++ b/dev/build-libs.js
@@ -64,6 +64,7 @@ export async function buildLibs() {
const schemaFileNames = fs.readdirSync(schemaDir);
const schemas = schemaFileNames.map((schemaFileName) => {
/** @type {import('ajv').AnySchema} */
+ // eslint-disable-next-line sonarjs/prefer-immediate-return
const result = parseJson(fs.readFileSync(path.join(schemaDir, schemaFileName), {encoding: 'utf8'}));
return result;
});
diff --git a/dev/data-error.js b/dev/data-error.js
index 5659245b..eb7f71bc 100644
--- a/dev/data-error.js
+++ b/dev/data-error.js
@@ -18,12 +18,14 @@
/**
* Schema validation error type.
*/
-class DataError extends Error {
+export class DataError extends Error {
/**
* @param {string} message
*/
constructor(message) {
super(message);
+ /** @type {string} */
+ this.name = 'DataError';
/** @type {unknown} */
this._data = void 0;
}
@@ -32,7 +34,3 @@ class DataError extends Error {
get data() { return this._data; }
set data(value) { this._data = value; }
}
-
-module.exports = {
- DataError
-};
diff --git a/dev/generate-css-json.js b/dev/generate-css-json.js
index 26bdfa64..a837c9e2 100644
--- a/dev/generate-css-json.js
+++ b/dev/generate-css-json.js
@@ -101,11 +101,11 @@ export function formatRulesJson(rules) {
for (const {selectors, styles} of rules) {
if (ruleIndex > 0) { result += ','; }
result += `\n${indent1}{\n${indent2}"selectors": `;
- if (selectors.length === 1) {
- result += `[${JSON.stringify(selectors[0], null, 4)}]`;
- } else {
- result += JSON.stringify(selectors, null, 4).replace(/\n/g, '\n' + indent2);
- }
+ result += (
+ selectors.length === 1 ?
+ `[${JSON.stringify(selectors[0], null, 4)}]` :
+ JSON.stringify(selectors, null, 4).replace(/\n/g, '\n' + indent2)
+ );
result += `,\n${indent2}"styles": [`;
let styleIndex = 0;
for (const [key, value] of styles) {
diff --git a/dev/lib/dexie.js b/dev/lib/dexie.js
index ffbd2923..83015e25 100644
--- a/dev/lib/dexie.js
+++ b/dev/lib/dexie.js
@@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import Dexie from 'dexie';
-import 'dexie-export-import';
+export {default as Dexie} from 'dexie';
-export {Dexie};
+import 'dexie-export-import';
diff --git a/dev/schema-validate.js b/dev/schema-validate.js
index d1ffcf82..3ad247d9 100644
--- a/dev/schema-validate.js
+++ b/dev/schema-validate.js
@@ -18,6 +18,7 @@
import Ajv from 'ajv';
import {readFileSync} from 'fs';
+import {fileURLToPath} from 'url';
import {JsonSchema} from '../ext/js/data/json-schema.js';
import {DataError} from './data-error.js';
import {parseJson} from './json.js';
@@ -32,7 +33,7 @@ class JsonSchemaAjv {
strictTuples: false,
allowUnionTypes: true
});
- const metaSchemaPath = require.resolve('ajv/dist/refs/json-schema-draft-07.json');
+ const metaSchemaPath = fileURLToPath(import.meta.resolve('ajv/dist/refs/json-schema-draft-07.json'));
/** @type {import('ajv').AnySchemaObject} */
const metaSchema = parseJson(readFileSync(metaSchemaPath, {encoding: 'utf8'}));
ajv.addMetaSchema(metaSchema);
diff --git a/dev/util.js b/dev/util.js
index 89bd95da..eee16964 100644
--- a/dev/util.js
+++ b/dev/util.js
@@ -40,10 +40,8 @@ export function getAllFiles(baseDirectory, predicate = null) {
if (typeof predicate !== 'function' || predicate(relativeFileName, false)) {
results.push(relativeFileName);
}
- } else if (stats.isDirectory()) {
- if (typeof predicate !== 'function' || predicate(relativeFileName, true)) {
- directories.push(fullFileName);
- }
+ } else if (stats.isDirectory() && (typeof predicate !== 'function' || predicate(relativeFileName, true))) {
+ directories.push(fullFileName);
}
}
}