Skip to content

Commit

Permalink
Merge branch 'master' into language-select
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Feb 15, 2024
2 parents d639e25 + 9432e4b commit bcd6d1d
Show file tree
Hide file tree
Showing 81 changed files with 3,388 additions and 317 deletions.
107 changes: 105 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"jsonc",
"unused-imports",
"@typescript-eslint",
"@stylistic"
"@stylistic",
"unicorn",
"sonarjs",
"import"
],
"ignorePatterns": [
"/ext/lib/",
Expand Down Expand Up @@ -247,7 +250,107 @@

"eslint-comments/no-unused-disable": "error",

"unused-imports/no-unused-imports": "error"
"unused-imports/no-unused-imports": "error",

"import/extensions": ["error", "ignorePackages"],

"unicorn/catch-error-name": ["error", {"ignore": ["^(e|error2?)$"]}],
"unicorn/custom-error-definition": "error",
"unicorn/empty-brace-spaces": "error",
"unicorn/error-message": "error",
"unicorn/expiring-todo-comments": "error",
"unicorn/explicit-length-check": "error",
"unicorn/new-for-builtins": "error",
"unicorn/no-abusive-eslint-disable": "error",
"unicorn/no-array-for-each": "error",
"unicorn/no-array-method-this-argument": "error",
"unicorn/no-array-push-push": "error",
"unicorn/no-array-reduce": "error",
"unicorn/no-console-spaces": "error",
"unicorn/no-document-cookie": "error",
"unicorn/no-empty-file": "error",
"unicorn/no-hex-escape": "error",
"unicorn/no-instanceof-array": "error",
"unicorn/no-invalid-remove-event-listener": "error",
"unicorn/no-lonely-if": "error",
"unicorn/no-nested-ternary": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-object-as-default-parameter": "error",
"unicorn/no-static-only-class": "error",
"unicorn/no-thenable": "error",
"unicorn/no-unnecessary-await": "error",
"unicorn/no-unnecessary-polyfills": "error",
"unicorn/no-unreadable-array-destructuring": "error",
"unicorn/no-unreadable-iife": "error",
"unicorn/no-useless-fallback-in-spread": "error",
"unicorn/no-useless-length-check": "error",
"unicorn/no-useless-promise-resolve-reject": "error",
"unicorn/no-useless-spread": "error",
"unicorn/no-useless-switch-case": "error",
"unicorn/no-useless-undefined": "error",
"unicorn/no-zero-fractions": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-default-parameters": "error",
"unicorn/prefer-dom-node-dataset": "error",
"unicorn/prefer-dom-node-text-content": "error",
"unicorn/prefer-event-target": "error",
"unicorn/prefer-export-from": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-keyboard-event-key": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-modern-math-apis": "error",
"unicorn/prefer-module": "error",
"unicorn/prefer-native-coercion-functions": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-number-properties": "error",
"unicorn/prefer-object-from-entries": "error",
"unicorn/prefer-prototype-methods": "error",
"unicorn/prefer-reflect-apply": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-set-has": "error",
"unicorn/prefer-set-size": "error",
"unicorn/prefer-spread": "error",
"unicorn/prefer-string-starts-ends-with": "error",
"unicorn/prefer-string-trim-start-end": "error",
"unicorn/prefer-switch": "error",
"unicorn/prefer-ternary": "error",
"unicorn/relative-url-style": "error",
"unicorn/require-array-join-separator": "error",
"unicorn/require-number-to-fixed-digits-argument": "error",
"unicorn/template-indent": "error",
"unicorn/throw-new-error": "error",

"sonarjs/max-switch-cases": "error",
"sonarjs/no-all-duplicated-branches": "error",
"sonarjs/no-collapsible-if": "error",
"sonarjs/no-collection-size-mischeck": "error",
"sonarjs/no-duplicated-branches": "error",
"sonarjs/no-element-overwrite": "error",
"sonarjs/no-empty-collection": "error",
"sonarjs/no-extra-arguments": "error",
"sonarjs/no-gratuitous-expressions": "error",
"sonarjs/no-identical-conditions": "error",
"sonarjs/no-identical-expressions": "error",
"sonarjs/no-identical-functions": "error",
"sonarjs/no-ignored-return": "error",
"sonarjs/no-inverted-boolean-check": "error",
"sonarjs/no-one-iteration-loop": "error",
"sonarjs/no-redundant-boolean": "error",
"sonarjs/no-redundant-jump": "error",
"sonarjs/no-same-line-conditional": "error",
"sonarjs/no-unused-collection": "error",
"sonarjs/no-use-of-empty-return-value": "error",
"sonarjs/no-useless-catch": "error",
"sonarjs/non-existent-operator": "error",
"sonarjs/prefer-immediate-return": "error",
"sonarjs/prefer-object-literal": "error",
"sonarjs/prefer-single-boolean-return": "error",
"sonarjs/prefer-while": "error"
},
"overrides": [
{
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
env:
CI: true

- name: Test JSON
run: npm run test-json
env:
CI: true

- name: Build Legal
run: npm run license-report

Expand Down
10 changes: 4 additions & 6 deletions dev/bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions dev/build-libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
8 changes: 3 additions & 5 deletions dev/data-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -32,7 +34,3 @@ class DataError extends Error {
get data() { return this._data; }
set data(value) { this._data = value; }
}

module.exports = {
DataError
};
10 changes: 5 additions & 5 deletions dev/generate-css-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions dev/lib/dexie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
17 changes: 4 additions & 13 deletions dev/manifest-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import {parseJson} from './json.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));

/**
* @template [T=unknown]
* @param {T} value
* @returns {T}
*/
function clone(value) {
return parseJson(JSON.stringify(value));
}


export class ManifestUtil {
constructor() {
Expand Down Expand Up @@ -70,7 +61,7 @@ export class ManifestUtil {
}
}

return clone(this._manifest);
return structuredClone(this._manifest);
}

/**
Expand Down Expand Up @@ -189,7 +180,7 @@ export class ManifestUtil {
const {start, deleteCount, items} = modification;
/** @type {unknown[]} */
const value = this._getObjectProperties(manifest, path2, path2.length);
const itemsNew = items.map((v) => clone(v));
const itemsNew = items.map((v) => structuredClone(v));
value.splice(start, deleteCount, ...itemsNew);
}
break;
Expand Down Expand Up @@ -229,7 +220,7 @@ export class ManifestUtil {
const {items} = modification;
/** @type {unknown[]} */
const value = this._getObjectProperties(manifest, path2, path2.length);
const itemsNew = items.map((v) => clone(v));
const itemsNew = items.map((v) => structuredClone(v));
value.push(...itemsNew);
}
break;
Expand Down Expand Up @@ -335,7 +326,7 @@ export class ManifestUtil {
* @returns {import('dev/manifest').Manifest}
*/
_createVariantManifest(manifest, variant) {
let modifiedManifest = clone(manifest);
let modifiedManifest = structuredClone(manifest);
for (const {modifications} of this._getInheritanceChain(variant)) {
modifiedManifest = this._applyModifications(modifiedManifest, modifications);
}
Expand Down
3 changes: 2 additions & 1 deletion dev/schema-validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions dev/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Loading

0 comments on commit bcd6d1d

Please sign in to comment.