From bbb110a0c08f56ba31d7ca578bc8ec9204f2f3fc Mon Sep 17 00:00:00 2001 From: Daniel Freytag Date: Tue, 7 Jan 2025 09:56:08 +0100 Subject: [PATCH] refact: swap super-linter for repo-specific config --- .editorconfig | 2 +- .github/linters/gitleaks.toml | 10 ---- .github/linters/hadolint.yaml | 11 ---- .github/linters/jscpd.json | 6 --- .github/linters/terrascan.yaml | 13 ----- .github/linters/yamllint.yaml | 7 --- .github/workflows/linter.yml | 7 +-- .markdownlint.yaml | 35 ------------ .stylelintrc.json | 20 ------- .yarnrc.yml | 3 -- eslint.config.mjs | 36 ++++++++----- packages/storage-wrapper/createUrl.js | 10 +--- packages/storage-wrapper/delete.js | 5 +- packages/storage-wrapper/index.js | 3 +- packages/storage-wrapper/load.js | 16 ++---- packages/storage-wrapper/move.js | 15 ++---- packages/storage-wrapper/save.js | 4 +- packages/undici/README.md | 6 +-- packages/undici/request.js | 26 +++------ scripts/ard/categories.js | 13 ++--- tests/ard.test.js | 4 +- tests/date.test.js | 30 +++-------- tests/numbers.test.js | 40 ++++---------- tests/strings.test.js | 78 +++++++-------------------- utils/date/getDateHourMinutes.js | 3 +- utils/date/getDayMonthYear.js | 3 +- utils/date/getFullRelativeTime.js | 3 +- utils/date/getYearMonthDay.js | 3 +- utils/numbers/getSum.js | 3 +- utils/numbers/roundTo.js | 2 +- utils/strings/isObject.js | 3 +- 31 files changed, 96 insertions(+), 324 deletions(-) delete mode 100644 .github/linters/gitleaks.toml delete mode 100644 .github/linters/hadolint.yaml delete mode 100644 .github/linters/jscpd.json delete mode 100644 .github/linters/terrascan.yaml delete mode 100644 .github/linters/yamllint.yaml delete mode 100644 .markdownlint.yaml delete mode 100644 .stylelintrc.json delete mode 100644 .yarnrc.yml diff --git a/.editorconfig b/.editorconfig index a376964..866cda1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ charset = utf-8 end_of_line = lf indent_style = tab indent_size = 8 -print_width = 120 +max_line_length = 120 trim_trailing_whitespace = true insert_final_newline = true diff --git a/.github/linters/gitleaks.toml b/.github/linters/gitleaks.toml deleted file mode 100644 index 570a695..0000000 --- a/.github/linters/gitleaks.toml +++ /dev/null @@ -1,10 +0,0 @@ -# example see https://github.com/github/super-linter/blob/main/TEMPLATES/.gitleaks.toml -# configuration see https://github.com/zricethezav/gitleaks#configuration - -title = "gitleaks config" - -useDefault = true - -[allowlist] - description = "Allowlisted files" - paths = ['''(default_host.key)$'''] diff --git a/.github/linters/hadolint.yaml b/.github/linters/hadolint.yaml deleted file mode 100644 index 5f1e8e8..0000000 --- a/.github/linters/hadolint.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# Dockerfile linter https://github.com/hadolint/hadolint - -failure-threshold: error - -ignored: - # Using latest is prone to errors if the image will ever update - - DL3007 - # Pin versions in apk add - - DL3018 - # Use absolute WORKDIR - - DL3000 diff --git a/.github/linters/jscpd.json b/.github/linters/jscpd.json deleted file mode 100644 index 9324c4e..0000000 --- a/.github/linters/jscpd.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "threshold": 8, - "reporters": ["consoleFull"], - "ignore": ["**/models/*.json"], - "absolute": true -} diff --git a/.github/linters/terrascan.yaml b/.github/linters/terrascan.yaml deleted file mode 100644 index fdec238..0000000 --- a/.github/linters/terrascan.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# terrascan configuration file https://github.com/accurics/terrascan/blob/master/config/terrascan.toml -# list of policies https://runterrascan.io/docs/policies/ - -severity: - level: 'medium' - -# scan and skip rules configuration -rules: - # skip rules (list of rules to skip) - skip-rules: - # skip service account at project-level check https://runterrascan.io/docs/policies/gcp/#google_project_iam_member - # https://github.com/tenable/terrascan/blob/8ae13452f91b9040038166c1b10e0f4191966ddd/pkg/policies/opa/rego/gcp/google_project_iam_member/accurics.gcp.IAM.137.json - - 'AC_GCP_0006' diff --git a/.github/linters/yamllint.yaml b/.github/linters/yamllint.yaml deleted file mode 100644 index 3f1bbe3..0000000 --- a/.github/linters/yamllint.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -extends: default - -rules: - document-start: disable - line-length: - max: 120 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index b90d6a6..f12d21b 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -3,8 +3,6 @@ name: Linter on: workflow_dispatch: pull_request: - branches-ignore: - - dependabot/** jobs: lint: @@ -21,7 +19,10 @@ jobs: bun-version: latest - name: 📦 Install Dependencies - run: bun install + run: bun install --frozen-lockfile - name: 📚 Lint Code Base run: bun run lint + + - name: 📚 Run Tests + run: bun run test diff --git a/.markdownlint.yaml b/.markdownlint.yaml deleted file mode 100644 index f49d30e..0000000 --- a/.markdownlint.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# see config https://github.com/DavidAnson/markdownlint#optionsconfig -# see example file https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml -# see rules https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md -# recommended VS Code plugin: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint - -# Default state for all rules -default: true - -# Unordered list style -MD004: true - -MD007: - # Unordered list indentation - indent: 2 - -# MD013/line-length - Line length -MD013: - # Number of characters - line_length: 808 - -MD026: - # List of not allowed - punctuation: '.,;:!。,;:' - -# Ordered list item prefix -MD029: false - -# Allow inline HTML -MD033: false - -# Emphasis used instead of a heading -MD036: false - -# Error on blank lines -blank_lines: false diff --git a/.stylelintrc.json b/.stylelintrc.json deleted file mode 100644 index b662cfc..0000000 --- a/.stylelintrc.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "defaultSeverity": "warning", - "extends": [ - "stylelint-config-standard-scss", - "stylelint-config-recommended-vue/scss" - ], - "ignoreFiles": [ - "**/static-ui/dist/*", - "**/ati-smarttag.js", - "**/skycons.js" - ], - "rules": { - "declaration-empty-line-before": null, - "indentation": "tab", - "no-descending-specificity": null, - "property-no-vendor-prefix": null, - "selector-class-pattern": null, - "selector-not-notation": null - } -} diff --git a/.yarnrc.yml b/.yarnrc.yml deleted file mode 100644 index 4553d9d..0000000 --- a/.yarnrc.yml +++ /dev/null @@ -1,3 +0,0 @@ -enableTelemetry: false - -nodeLinker: node-modules diff --git a/eslint.config.mjs b/eslint.config.mjs index 1283bd7..88c9df3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,4 +1,4 @@ -import { audiolab } from '@swrlab/style-guide/eslint/index' +import { audiolab } from '@swrlab/style-guide/eslint/presets' export default audiolab( [ @@ -7,14 +7,27 @@ export default audiolab( }, { rules: { - // previous config (does not trigger errors) - // 'import/no-extraneous-dependencies': 0, - // radix: 0, - // 'no-param-reassign': [2, { props: false }], - // 'no-restricted-syntax': 0, - // 'no-underscore-dangle': 0, - // 'no-return-assign': ['error', 'except-parens'], - // 'one-var': 0, + 'n/no-missing-import': 'off', + 'n/no-path-concat': 'off', + // 'vue/no-unused-component': 'off', + 'vue/no-unused-components': 'off', + 'n/no-unsupported-features/node-builtins': 'off', + 'n/no-missing-require': 'off', + 'no-unused-vars': 'off', + eqeqeq: 'off', + 'no-undef': 'off', + // 'prefer-const': 'off', + 'import/no-extraneous-dependencies': 'off', + 'n/no-extraneous-require': 'off', + + 'vue/no-deprecated-destroyed-lifecycle': 'off', + 'prefer-template': 'off', + 'sonarjs/cognitive-complexity': 'off', + + // fixable + 'one-var': 'off', + 'prefer-const': 'off', + 'no-var': 'off', // should be fixed / easy to fix 'prefer-promise-reject-errors': 'off', @@ -24,7 +37,6 @@ export default audiolab( 'n/no-unpublished-import': 'off', 'n/no-unpublished-require': 'off', 'eslint-comments/require-description': 'off', - 'vue/multi-word-component-names': 'off', // could be fixed when converting to ESM 'import/order': 'off', // a bit more complex to fix (but nice idea in general) @@ -32,13 +44,11 @@ export default audiolab( 'no-console': 'off', 'func-names': 'off', 'jsonc/sort-keys': 'off', - - // harder to fix }, }, ], { - prettier: true, + prettier: false, comments: true, } ) diff --git a/packages/storage-wrapper/createUrl.js b/packages/storage-wrapper/createUrl.js index 878b588..ad3eb36 100644 --- a/packages/storage-wrapper/createUrl.js +++ b/packages/storage-wrapper/createUrl.js @@ -20,19 +20,13 @@ module.exports = async function (uri, ttl) { } // create link - const [url] = await this.sdk.gs - .bucket(bucket) - .file(path) - .getSignedUrl(config) + const [url] = await this.sdk.gs.bucket(bucket).file(path).getSignedUrl(config) // return link return Promise.resolve(url) } - if ( - uri.substr(0, 7).toLowerCase() === 'http://' || - uri.substr(0, 8).toLowerCase() === 'https://' - ) { + if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') { // return link return Promise.resolve(uri) } diff --git a/packages/storage-wrapper/delete.js b/packages/storage-wrapper/delete.js index ed52f21..991f71f 100644 --- a/packages/storage-wrapper/delete.js +++ b/packages/storage-wrapper/delete.js @@ -26,10 +26,7 @@ module.exports = async function (uri) { return Promise.resolve() } - if ( - uri.substr(0, 7).toLowerCase() === 'http://' || - uri.substr(0, 8).toLowerCase() === 'https://' - ) { + if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') { // return ok return Promise.resolve() } diff --git a/packages/storage-wrapper/index.js b/packages/storage-wrapper/index.js index 0ad81e0..362e0c4 100644 --- a/packages/storage-wrapper/index.js +++ b/packages/storage-wrapper/index.js @@ -11,8 +11,7 @@ const { Storage } = require('@google-cloud/storage') // create wrapper function StorageWrapper(config) { // check config - if (!config || !config.gs) - return Promise.reject(new Error('storage config invalid')) + if (!config || !config.gs) return Promise.reject(new Error('storage config invalid')) // enable SDKs this.sdk = {} diff --git a/packages/storage-wrapper/load.js b/packages/storage-wrapper/load.js index 96645d6..e38c3f8 100644 --- a/packages/storage-wrapper/load.js +++ b/packages/storage-wrapper/load.js @@ -23,19 +23,13 @@ module.exports = async function (uri, _logPrefix, options) { const path = structure.join('/') // load file - const file = await this.sdk.gs - .bucket(bucket) - .file(path) - .download() + const file = await this.sdk.gs.bucket(bucket).file(path).download() // return file return Promise.resolve(file[0]) } - if ( - uri.substr(0, 7).toLowerCase() === 'http://' || - uri.substr(0, 8).toLowerCase() === 'https://' - ) { + if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') { // public http(s) endpoint const file = await undici(uri, { timeout: options?.timeout, @@ -47,11 +41,7 @@ module.exports = async function (uri, _logPrefix, options) { return Promise.resolve(file.buffer) } - return Promise.reject( - new Error( - `fetching url failed with status > ${file.statusCode}` - ) - ) + return Promise.reject(new Error(`fetching url failed with status > ${file.statusCode}`)) } // local file diff --git a/packages/storage-wrapper/move.js b/packages/storage-wrapper/move.js index 345b3a9..c7b212b 100644 --- a/packages/storage-wrapper/move.js +++ b/packages/storage-wrapper/move.js @@ -5,10 +5,7 @@ */ module.exports = async function (sourceUri, destinationUri, keepOriginal) { - if ( - sourceUri.substr(0, 5).toLowerCase() === 'gs://' && - destinationUri.substr(0, 5).toLowerCase() === 'gs://' - ) { + if (sourceUri.substr(0, 5).toLowerCase() === 'gs://' && destinationUri.substr(0, 5).toLowerCase() === 'gs://') { // google to google transfer // parse source @@ -19,16 +16,10 @@ module.exports = async function (sourceUri, destinationUri, keepOriginal) { // move file within gcs if (keepOriginal !== true) { // move file - await this.sdk.gs - .bucket(bucket) - .file(path) - .move(destinationUri) + await this.sdk.gs.bucket(bucket).file(path).move(destinationUri) } else { // copy file - await this.sdk.gs - .bucket(bucket) - .file(path) - .copy(destinationUri) + await this.sdk.gs.bucket(bucket).file(path).copy(destinationUri) } // return ok diff --git a/packages/storage-wrapper/save.js b/packages/storage-wrapper/save.js index a3b2ef9..640c2c7 100644 --- a/packages/storage-wrapper/save.js +++ b/packages/storage-wrapper/save.js @@ -51,9 +51,7 @@ module.exports = async function (uri, buffer, _logPrefix, resumable) { } // upload file to gcs - await this.sdk.gs - .bucket(bucket) - .upload(tempFilePath, bucketConfig) + await this.sdk.gs.bucket(bucket).upload(tempFilePath, bucketConfig) // delete local temp file await deleteLocalFile(this, tempFilePath) diff --git a/packages/undici/README.md b/packages/undici/README.md index 8a8fb7d..e54ae30 100644 --- a/packages/undici/README.md +++ b/packages/undici/README.md @@ -44,9 +44,9 @@ Advanced usage: ```js const data = await undici(someApiUrl, { method: 'GET', - timeout: 6e3, - reject: false, - maxRedirections: 5 + timeout: 6e3, + reject: false, + maxRedirections: 5, }) ``` diff --git a/packages/undici/request.js b/packages/undici/request.js index 4a0b5a6..462edd8 100644 --- a/packages/undici/request.js +++ b/packages/undici/request.js @@ -1,5 +1,5 @@ // load node utils -const undici = require('undici') +const undici = require('node:undici') const AbortController = require('abort-controller') // fetch options and utils @@ -17,10 +17,7 @@ module.exports = async (url, options) => { // calculcate redirect const maxRedirections = - options?.maxRedirections !== null && - options?.maxRedirections !== undefined - ? options.maxRedirections - : 5 + options?.maxRedirections !== null && options?.maxRedirections !== undefined ? options.maxRedirections : 5 // prepare options const requestOptions = { @@ -37,27 +34,20 @@ module.exports = async (url, options) => { } // make actual request - const { statusCode, headers, trailers, body } = await undici.request( - url, - requestOptions - ) + const { statusCode, headers, trailers, body } = await undici.request(url, requestOptions) // remove timeout since request finished beforehand clearTimeout(abortTimeout) // set ok const ok = statusCode >= 200 && statusCode < 300 - if (!ok && (!options || options?.reject !== false)) - return Promise.reject({ statusCode, ok, headers, url }) + if (!ok && (!options || options?.reject !== false)) return Promise.reject({ statusCode, ok, headers, url }) // turn stream into string const { string, buffer } = await convertReadableStream(body) // detect/ set redirect - const redirect = - statusCode >= 300 && statusCode < 400 && headers.location - ? new URL(headers.location, url) - : null + const redirect = statusCode >= 300 && statusCode < 400 && headers.location ? new URL(headers.location, url) : null // fetch header vars const contentType = headers['content-type'] @@ -65,11 +55,7 @@ module.exports = async (url, options) => { // parse json if set let json try { - json = - contentType?.indexOf('application/json') !== -1 - ? JSON.parse(string) - : null - // eslint-disable-next-line no-unused-vars + json = contentType?.indexOf('application/json') !== -1 ? JSON.parse(string) : null } catch (error) { json = null } diff --git a/scripts/ard/categories.js b/scripts/ard/categories.js index 033dc16..9dd23f6 100644 --- a/scripts/ard/categories.js +++ b/scripts/ard/categories.js @@ -21,14 +21,10 @@ const crawl = async () => { const remapItem = (item) => { // remap children if available - const children = item.children - ? item.children.map(remapItem) - : null + const children = item.children ? item.children.map(remapItem) : null // set main or sub prefix - const prefix = item.children - ? CORE_PREFIX_GENRE - : CORE_PREFIX_SUBGENRE + const prefix = item.children ? CORE_PREFIX_GENRE : CORE_PREFIX_SUBGENRE // build item const category = { @@ -49,10 +45,7 @@ const crawl = async () => { const tree = categories.map(remapItem) - await storage.save( - 'data/ard/categories.json', - JSON.stringify({ tree, list }, null, '\t') - ) + await storage.save('data/ard/categories.json', JSON.stringify({ tree, list }, null, '\t')) } crawl() diff --git a/tests/ard.test.js b/tests/ard.test.js index 36cabbc..921e5ac 100644 --- a/tests/ard.test.js +++ b/tests/ard.test.js @@ -15,9 +15,7 @@ const { createHashedId } = require('../packages/ard') describe('Test ARD Package', () => { describe('Test ARD-CoreID Hash', () => { it("createHashedId('test') = 0c171b2e54a30c11", () => { - expect(createHashedId('test')).to.equal( - '0c171b2e54a30c11' - ) + expect(createHashedId('test')).to.equal('0c171b2e54a30c11') }) }) }) diff --git a/tests/date.test.js b/tests/date.test.js index db39523..8a84d7d 100644 --- a/tests/date.test.js +++ b/tests/date.test.js @@ -13,70 +13,56 @@ const date = require('../packages/date') const testDate = '2038-01-19T03:14:08.000' const relativeTime = 2147483647000 - new Date().getTime() -const relativeYears = parseInt(relativeTime / (1000 * 60 * 60 * 24 * 365), 10) +const relativeYears = Number.parseInt(relativeTime / (1000 * 60 * 60 * 24 * 365), 10) // Test DateTime Package describe('Test DateTime Package', () => { describe('Test getDateHourMinutes', () => { const testResult = 'Di, 19. Januar 2038 - 03:14 Uhr' it(`getDateHourMinutes('${testDate}') = '${testResult}'`, () => { - expect(date.getDateHourMinutes(testDate)).to.equal( - testResult - ) + expect(date.getDateHourMinutes(testDate)).to.equal(testResult) }) }) describe('Test getDayMonthYear', () => { const testResult = 'Di, 19. Januar 2038' it(`getDayMonthYear('${testDate}') = '${testResult}'`, () => { - expect(date.getDayMonthYear(testDate)).to.equal( - testResult - ) + expect(date.getDayMonthYear(testDate)).to.equal(testResult) }) }) describe('Test getFullRelativeTime', () => { const testResult = `Di, 19. Januar 2038 - 03:14 Uhr (in ${relativeYears} Jahren)` it(`getFullRelativeTime('${testDate}') = '${testResult}'`, () => { - expect(date.getFullRelativeTime(testDate)).to.equal( - testResult - ) + expect(date.getFullRelativeTime(testDate)).to.equal(testResult) }) }) describe('Test getHourMinutes', () => { const testResult = '03:14' it(`getHourMinutes('${testDate}') = '${testResult}'`, () => { - expect(date.getHourMinutes(testDate)).to.equal( - testResult - ) + expect(date.getHourMinutes(testDate)).to.equal(testResult) }) }) describe('Test getIsoRelativeTime', () => { const testResult = `${testDate} (in ${relativeYears} Jahren)` it(`getIsoRelativeTime('${testDate}') = '${testResult}'`, () => { - expect(date.getIsoRelativeTime(testDate)).to.equal( - testResult - ) + expect(date.getIsoRelativeTime(testDate)).to.equal(testResult) }) }) describe('Test getRelativeTime', () => { const testResult = `in ${relativeYears} Jahren` it(`getRelativeTime('${testDate}') = '${testResult}'`, () => { - expect(date.getRelativeTime(testDate)).to.equal( - testResult - ) + expect(date.getRelativeTime(testDate)).to.equal(testResult) }) }) describe('Test getYearMonthDay', () => { const testResult = '20380119' it(`getYearMonthDay('${testDate}') = '${testResult}'`, () => { - expect(date.getYearMonthDay(testDate)).to.equal( - testResult - ) + expect(date.getYearMonthDay(testDate)).to.equal(testResult) }) }) diff --git a/tests/numbers.test.js b/tests/numbers.test.js index e96f00b..882ea7e 100644 --- a/tests/numbers.test.js +++ b/tests/numbers.test.js @@ -25,39 +25,27 @@ describe('Test Numbers Package', () => { describe('Test addTrailingZeros', () => { it("addTrailingZeros(1, 5) = '1.00000'", () => { - expect(numbers.addTrailingZeros(1, 5)).to.equal( - '1.00000' - ) + expect(numbers.addTrailingZeros(1, 5)).to.equal('1.00000') }) it("addTrailingZeros(1.1, 5) = '1.10000'", () => { - expect(numbers.addTrailingZeros(1.1, 5)).to.equal( - '1.10000' - ) + expect(numbers.addTrailingZeros(1.1, 5)).to.equal('1.10000') }) it("addTrailingZeros('1.2', 5) = '1.20000'", () => { - expect(numbers.addTrailingZeros('1.2', 5)).to.equal( - '1.20000' - ) + expect(numbers.addTrailingZeros('1.2', 5)).to.equal('1.20000') }) it("addTrailingZeros(2, 2, ',') = '2,00'", () => { - expect(numbers.addTrailingZeros(2, 2, ',')).to.equal( - '2,00' - ) + expect(numbers.addTrailingZeros(2, 2, ',')).to.equal('2,00') }) it("addTrailingZeros(2.1, 2, ',') = '2,10'", () => { - expect(numbers.addTrailingZeros(2.1, 2, ',')).to.equal( - '2,10' - ) + expect(numbers.addTrailingZeros(2.1, 2, ',')).to.equal('2,10') }) it("addTrailingZeros('2,2', 2, ','') = '2,20'", () => { - expect( - numbers.addTrailingZeros('2,2', 2, ',') - ).to.equal('2,20') + expect(numbers.addTrailingZeros('2,2', 2, ',')).to.equal('2,20') }) }) @@ -67,9 +55,7 @@ describe('Test Numbers Package', () => { }) it('getAverage([1.2, 2.4, 3.6], 1) = 2.4', () => { - expect(numbers.getAverage([1.2, 2.4, 3.6], 1)).to.equal( - 2.4 - ) + expect(numbers.getAverage([1.2, 2.4, 3.6], 1)).to.equal(2.4) }) }) @@ -85,15 +71,11 @@ describe('Test Numbers Package', () => { describe('Test getRandomInRange', () => { it('getRandomInRange(1, 5) = 1,2,3,4 or 5', () => { - expect([1, 2, 3, 4, 5]).to.include( - numbers.getRandomInRange(1, 5) - ) + expect([1, 2, 3, 4, 5]).to.include(numbers.getRandomInRange(1, 5)) }) it('getRandomInRange(5, 9) = 5,6,7,8 or 9', () => { - expect([5, 6, 7, 8, 9]).to.include( - numbers.getRandomInRange(5, 9) - ) + expect([5, 6, 7, 8, 9]).to.include(numbers.getRandomInRange(5, 9)) }) }) @@ -139,9 +121,7 @@ describe('Test Numbers Package', () => { describe('Test toReadable', () => { it("toReadable(1234567) = '1.234.567'", () => { - expect(numbers.toReadable(1234567)).to.equal( - '1.234.567' - ) + expect(numbers.toReadable(1234567)).to.equal('1.234.567') }) }) }) diff --git a/tests/strings.test.js b/tests/strings.test.js index 3c9591f..cf7dfce 100644 --- a/tests/strings.test.js +++ b/tests/strings.test.js @@ -24,9 +24,7 @@ describe('Test Strings Package', () => { describe('Test getObjectLength', () => { it("getObjectLength({ hello: 'world' }) = 1", () => { - expect( - strings.getObjectLength({ hello: 'world' }) - ).to.equal(1) + expect(strings.getObjectLength({ hello: 'world' })).to.equal(1) }) it("getObjectLength({ hello: 'world', foo: 'bar' }) = 2", () => { @@ -45,9 +43,7 @@ describe('Test Strings Package', () => { }) it("isArray({ hello: 'world' }) = false", () => { - expect(strings.isArray({ hello: 'world' })).to.equal( - false - ) + expect(strings.isArray({ hello: 'world' })).to.equal(false) }) }) @@ -57,9 +53,7 @@ describe('Test Strings Package', () => { }) it("isEmptyArray(['hello world']) = false", () => { - expect(strings.isEmptyArray(['hello world'])).to.equal( - false - ) + expect(strings.isEmptyArray(['hello world'])).to.equal(false) }) }) @@ -69,9 +63,7 @@ describe('Test Strings Package', () => { }) it("isEmptyObject({ hello: 'world' }) = false", () => { - expect( - strings.isEmptyObject({ hello: 'world' }) - ).to.equal(false) + expect(strings.isEmptyObject({ hello: 'world' })).to.equal(false) }) }) @@ -81,23 +73,17 @@ describe('Test Strings Package', () => { }) it("isEmptyString('hello world') = false", () => { - expect(strings.isEmptyString('hello world')).to.equal( - false - ) + expect(strings.isEmptyString('hello world')).to.equal(false) }) }) describe('Test isIncluded', () => { it("isIncluded('hello world', 'hello') = true", () => { - expect( - strings.isIncluded('hello world', 'hello') - ).to.equal(true) + expect(strings.isIncluded('hello world', 'hello')).to.equal(true) }) it("isIncluded('hello world', 'earth') = false", () => { - expect( - strings.isIncluded('hello world', 'earth') - ).to.equal(false) + expect(strings.isIncluded('hello world', 'earth')).to.equal(false) }) }) @@ -113,9 +99,7 @@ describe('Test Strings Package', () => { describe('Test isObject', () => { it("isObject({ hello: 'world' }) = true", () => { - expect(strings.isObject({ hello: 'world' })).to.equal( - true - ) + expect(strings.isObject({ hello: 'world' })).to.equal(true) }) it("isObject('hello world') = false", () => { @@ -135,9 +119,7 @@ describe('Test Strings Package', () => { describe('Test notEmptyArray', () => { it("notEmptyArray(['hello world']) = true", () => { - expect(strings.notEmptyArray(['hello world'])).to.equal( - true - ) + expect(strings.notEmptyArray(['hello world'])).to.equal(true) }) it('notEmptyArray([]) = false', () => { @@ -147,9 +129,7 @@ describe('Test Strings Package', () => { describe('Test notEmptyObject', () => { it("notEmptyObject({ hello: 'world' }) = true", () => { - expect( - strings.notEmptyObject({ hello: 'world' }) - ).to.equal(true) + expect(strings.notEmptyObject({ hello: 'world' })).to.equal(true) }) it('notEmptyObject({}) = false', () => { @@ -159,9 +139,7 @@ describe('Test Strings Package', () => { describe('Test notNullOrUndefined', () => { it("notNullOrUndefined('hello world') = true", () => { - expect( - strings.notNullOrUndefined('hello world') - ).to.equal(true) + expect(strings.notNullOrUndefined('hello world')).to.equal(true) }) it('notNullOrUndefined(null) = false', () => { @@ -169,59 +147,41 @@ describe('Test Strings Package', () => { }) it('notNullOrUndefined(undefined) = false', () => { - expect(strings.notNullOrUndefined(undefined)).to.equal( - false - ) + expect(strings.notNullOrUndefined(undefined)).to.equal(false) }) }) describe('Test pluralize', () => { it("pluralize(1, 'Apple') = '1 Apple'", () => { - expect(strings.pluralize(1, 'Apple')).to.equal( - '1 Apple' - ) + expect(strings.pluralize(1, 'Apple')).to.equal('1 Apple') }) it("pluralize(1000, 'Apple') = '1.000 Apples'", () => { - expect(strings.pluralize(1000, 'Apple')).to.equal( - '1.000 Apples' - ) + expect(strings.pluralize(1000, 'Apple')).to.equal('1.000 Apples') }) it("pluralize(1, 'Child', 'Children') = '1 Child'", () => { - expect( - strings.pluralize(1, 'Child', 'Children') - ).to.equal('1 Child') + expect(strings.pluralize(1, 'Child', 'Children')).to.equal('1 Child') }) it("pluralize(1000, 'Child', 'Children') = '1.000 Children'", () => { - expect( - strings.pluralize(1000, 'Child', 'Children') - ).to.equal('1.000 Children') + expect(strings.pluralize(1000, 'Child', 'Children')).to.equal('1.000 Children') }) }) describe('Test removeDoubleSpaces', () => { it("removeDoubleSpaces('hello world')) = 'hello world'", () => { - expect( - strings.removeDoubleSpaces('hello world') - ).to.equal('hello world') + expect(strings.removeDoubleSpaces('hello world')).to.equal('hello world') }) it("removeDoubleSpaces('hello world once again')) = 'hello world once again'", () => { - expect( - strings.removeDoubleSpaces( - 'hello world once again' - ) - ).to.equal('hello world once again') + expect(strings.removeDoubleSpaces('hello world once again')).to.equal('hello world once again') }) }) describe('Test toHex', () => { it("toHex('hello world')) = '68656c6c6f20776f726c64'", () => { - expect(strings.toHex('hello world')).to.equal( - '68656c6c6f20776f726c64' - ) + expect(strings.toHex('hello world')).to.equal('68656c6c6f20776f726c64') }) }) }) diff --git a/utils/date/getDateHourMinutes.js b/utils/date/getDateHourMinutes.js index 738de47..fcc9704 100644 --- a/utils/date/getDateHourMinutes.js +++ b/utils/date/getDateHourMinutes.js @@ -2,5 +2,4 @@ const { DateTime } = require('luxon') // returns 'Di, 19. Januar 2038 - 03:14 Uhr' const dayHourMinutes = 'ccc, d. LLLL yyyy - HH:mm' -module.exports = (date) => - `${DateTime.fromISO(date).setLocale('de').toFormat(dayHourMinutes)} Uhr` +module.exports = (date) => `${DateTime.fromISO(date).setLocale('de').toFormat(dayHourMinutes)} Uhr` diff --git a/utils/date/getDayMonthYear.js b/utils/date/getDayMonthYear.js index a26c0a2..cc387c8 100644 --- a/utils/date/getDayMonthYear.js +++ b/utils/date/getDayMonthYear.js @@ -1,5 +1,4 @@ const { DateTime } = require('luxon') // returns 'Do, 1. Januar 1970' -module.exports = (date) => - DateTime.fromISO(date).setLocale('de').toFormat('ccc, d. LLLL yyyy') +module.exports = (date) => DateTime.fromISO(date).setLocale('de').toFormat('ccc, d. LLLL yyyy') diff --git a/utils/date/getFullRelativeTime.js b/utils/date/getFullRelativeTime.js index bc949d0..edcab2d 100644 --- a/utils/date/getFullRelativeTime.js +++ b/utils/date/getFullRelativeTime.js @@ -2,5 +2,4 @@ const getDateHourMinutes = require('./getDateHourMinutes') const getRelativeTime = require('./getRelativeTime') // returns 'Do, 1. Januar 1970 - 00:00 Uhr (in YY Jahren)' -module.exports = (date) => - `${getDateHourMinutes(date)} (${getRelativeTime(date)})` +module.exports = (date) => `${getDateHourMinutes(date)} (${getRelativeTime(date)})` diff --git a/utils/date/getYearMonthDay.js b/utils/date/getYearMonthDay.js index e5f460b..1b778a8 100644 --- a/utils/date/getYearMonthDay.js +++ b/utils/date/getYearMonthDay.js @@ -1,5 +1,4 @@ const { DateTime } = require('luxon') // get YYYYMMDD (returns '19700101') -module.exports = (date) => - DateTime.fromISO(date).setLocale('de').toFormat('yyyyLLdd') +module.exports = (date) => DateTime.fromISO(date).setLocale('de').toFormat('yyyyLLdd') diff --git a/utils/numbers/getSum.js b/utils/numbers/getSum.js index 77a2e7a..f91273e 100644 --- a/utils/numbers/getSum.js +++ b/utils/numbers/getSum.js @@ -1,5 +1,4 @@ // get sum from array of values const roundTo = require('./roundTo') -module.exports = (arr, decimals = 2) => - arr.reduce((a, b) => roundTo(a + b, decimals), 0) +module.exports = (arr, decimals = 2) => arr.reduce((a, b) => roundTo(a + b, decimals), 0) diff --git a/utils/numbers/roundTo.js b/utils/numbers/roundTo.js index edcbb4c..20a8964 100644 --- a/utils/numbers/roundTo.js +++ b/utils/numbers/roundTo.js @@ -1,5 +1,5 @@ +// eslint-disable-file prefer-template // https://gist.github.com/djD-REK/068cba3d430cf7abfddfd32a5d7903c3 module.exports = (number, decimal = 2) => { - // eslint-disable-next-line prefer-template return Number(Math.round(number + 'e' + decimal) + 'e-' + decimal) } diff --git a/utils/strings/isObject.js b/utils/strings/isObject.js index ca19a1d..086ace1 100644 --- a/utils/strings/isObject.js +++ b/utils/strings/isObject.js @@ -3,5 +3,4 @@ const isArray = require('./isArray') const notNullOrUndefined = require('./notNullOrUndefined') // check if a variable is really an object -module.exports = (value) => - notNullOrUndefined(value) && value instanceof Object && !isArray(value) +module.exports = (value) => notNullOrUndefined(value) && value instanceof Object && !isArray(value)