From c39f943e3c16adbc2e2acb5795ad460df4129fe4 Mon Sep 17 00:00:00 2001 From: Matthieu Guigon Date: Sun, 13 Nov 2022 11:48:28 +0100 Subject: [PATCH] Update github actions --- .eslintignore | 3 +- .eslintrc | 57 ++++++++++- .github/workflows/main.yml | 26 ----- .github/workflows/on-push.yml | 107 +++++++++++++++++++++ package.json | 1 + src/Environment.ts | 14 +-- src/Error/EnvironmentVariableParseError.ts | 2 +- src/StringDictionaryReader/ReadOnly.ts | 12 +-- src/StringDictionaryReader/index.ts | 2 +- src/index.ts | 6 +- yarn.lock | 28 +++++- 11 files changed, 210 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/on-push.yml diff --git a/.eslintignore b/.eslintignore index 76add87..6013fd8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ node_modules -dist \ No newline at end of file +dist +src/**/*.test.ts diff --git a/.eslintrc b/.eslintrc index 87a4a6a..1100cc2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], + "plugins": ["@typescript-eslint", "autofix"], "extends": [ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", @@ -15,6 +15,59 @@ "@typescript-eslint/explicit-module-boundary-types": ["error"], "@typescript-eslint/member-ordering": ["error"], "@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }], - "@typescript-eslint/no-non-null-assertion": ["error"] + "@typescript-eslint/no-non-null-assertion": ["error"], + "arrow-body-style": ["error", "as-needed"], + "quotes": ["error", "single"], + "spaced-comment": ["error"], + "no-duplicate-imports": ["error"], + "@typescript-eslint/consistent-type-imports": [ + "error", + { + "prefer": "type-imports", + } + ], + "comma-dangle": [ + "error", + { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "always-multiline", + "exports": "always-multiline", + "functions": "always-multiline" + } + ], + "autofix/no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_", + "ignoreRestSiblings": true, + "destructuredArrayIgnorePattern": "^_" + } + ], + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "classProperty", + "format": ["camelCase", "UPPER_CASE"], + "modifiers": ["private", "readonly", "static"] + }, + { + "selector": "default", + "format": ["camelCase"] + }, + { + "selector": "variable", + "format": ["camelCase", "UPPER_CASE"] + }, + { + "selector": "typeLike", + "format": ["PascalCase"] + }, + { + "selector": "enumMember", + "format": ["PascalCase"] + } + ], + "brace-style": ["error"] } } diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index f0de2d4..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: update -on: - push: - branches: - - main -jobs: - coverage: - runs-on: ubuntu-20.04 - timeout-minutes: 5 - steps: - - name: checkout code - uses: actions/checkout@v3 - - name: setup node.js - uses: actions/setup-node@v3 - with: - node-version: 16 - - name: install dependencies - run: npm install - - name: Test & publish code coverage - uses: paambaati/codeclimate-action@v3.2.0 - env: - CC_TEST_REPORTER_ID: d14fc03e4d27016e3da2f8eb6d03abdaf1ae1eb6b0ef5cd260cb45609e6a126d - with: - coverageCommand: yarn run test:coverage - debug: true - coverageLocations: ${{github.workspace}}/coverage/*.lcov:lcov diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml new file mode 100644 index 0000000..2c89281 --- /dev/null +++ b/.github/workflows/on-push.yml @@ -0,0 +1,107 @@ +name: update +on: + push: + branches: + - 'feature/**' + - 'bugfix/**' +jobs: + setup: + runs-on: ubuntu-20.04 + timeout-minutes: 5 + steps: + - name: checkout code + uses: actions/checkout@v3 + - name: setup node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: install dependencies + run: npm install + - name: Zip code and environment variables + run: | + pwd + ls -lah + touch code.artifact.tar.gz + tar --exclude=code.artifact.tar.gz -czf code.artifact.tar.gz . + ls -lh code.artifact.tar.gz | awk '{ print "a tarball file named "$9" with a size of "$5" was successfully created."}' + - name: Upload code, env vars and dependencies artifacts + uses: actions/upload-artifact@v3 + with: + name: code.artifact + retention-days: 1 + path: code.artifact.tar.gz + + coverage: + needs: + - setup + runs-on: ubuntu-20.04 + timeout-minutes: 5 + steps: + - name: Download code, env vars artifacts + uses: actions/download-artifact@v3 + with: + name: code.artifact + path: . + - name: Unzip code and env vars + run: | + ls -la + ls -lh code.artifact.tar.gz | awk '{ print "a tarball file named "$9" with a size of "$5" was successfully recovered."}' + tar -xzf code.artifact.tar.gz + rm code.artifact.tar.gz + - name: setup node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Test + run: | + yarn run test:coverage + + lint: + needs: + - setup + runs-on: ubuntu-20.04 + timeout-minutes: 5 + steps: + - name: Download code, env vars artifacts + uses: actions/download-artifact@v3 + with: + name: code.artifact + path: . + - name: Unzip code and env vars + run: | + ls -la + ls -lh code.artifact.tar.gz | awk '{ print "a tarball file named "$9" with a size of "$5" was successfully recovered."}' + tar -xzf code.artifact.tar.gz + rm code.artifact.tar.gz + - name: setup node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: lint + run: | + yarn run lint + + build: + needs: + - setup + runs-on: ubuntu-20.04 + timeout-minutes: 5 + steps: + - name: Download code, env vars artifacts + uses: actions/download-artifact@v3 + with: + name: code.artifact + path: . + - name: Unzip code and env vars + run: | + ls -la + ls -lh code.artifact.tar.gz | awk '{ print "a tarball file named "$9" with a size of "$5" was successfully recovered."}' + tar -xzf code.artifact.tar.gz + rm code.artifact.tar.gz + - name: setup node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: build + run: | + yarn run build diff --git a/package.json b/package.json index 7e698bb..261722c 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@typescript-eslint/parser": "^5.42.1", "babel-jest": "^29.3.1", "eslint": "^8.27.0", + "eslint-plugin-autofix": "^1.1.0", "jest": "^29.3.1", "nodemon": "^2.0.20", "rimraf": "^3.0.2", diff --git a/src/Environment.ts b/src/Environment.ts index 5914fed..5a36dad 100644 --- a/src/Environment.ts +++ b/src/Environment.ts @@ -1,13 +1,13 @@ -import StringDictReaderReadOnly from "./StringDictionaryReader/ReadOnly"; +import StringDictReaderReadOnly from './StringDictionaryReader/ReadOnly'; enum EnvironmentName { - Development = "development", - Production = "production", - Test = "test", + Development = 'development', + Production = 'production', + Test = 'test', } class Environment extends StringDictReaderReadOnly { - private static readonly CURRENT_ENVIRONMENT_KEY = "NODE_ENV"; + private static readonly CURRENT_ENVIRONMENT_KEY = 'NODE_ENV'; private defaultEnvironmentValues: Record = {}; @@ -18,7 +18,7 @@ class Environment extends StringDictReaderReadOnly { public get content(): Record { return { ...this.defaultEnvironmentValues, - ...this.dict + ...this.dict, }; } @@ -44,7 +44,7 @@ class Environment extends StringDictReaderReadOnly { public getEnvName(): EnvironmentName | T { return this.get( Environment.CURRENT_ENVIRONMENT_KEY, - EnvironmentName.Development + EnvironmentName.Development, ) as EnvironmentName | T; } diff --git a/src/Error/EnvironmentVariableParseError.ts b/src/Error/EnvironmentVariableParseError.ts index 3bb2d0c..8205971 100644 --- a/src/Error/EnvironmentVariableParseError.ts +++ b/src/Error/EnvironmentVariableParseError.ts @@ -9,7 +9,7 @@ class EnvironmentVariableParseError extends Error { constructor( public readonly variableName: string, public readonly targetedType: TargetedType, - public readonly input: unknown + public readonly input: unknown, ) { super(`Could not parse environment variable "${variableName}" as ${targetedType}. Input was "${input}".`); } diff --git a/src/StringDictionaryReader/ReadOnly.ts b/src/StringDictionaryReader/ReadOnly.ts index 6f54872..c6f58d3 100644 --- a/src/StringDictionaryReader/ReadOnly.ts +++ b/src/StringDictionaryReader/ReadOnly.ts @@ -1,6 +1,6 @@ -import { createReadStream, existsSync, readFileSync, ReadStream } from "fs"; -import EnvironmentVariableParseError, { TargetedType } from "../Error/EnvironmentVariableParseError"; -import UndefinedEnvironmentVariableError from "../Error/UndefinedEnvironmentVariableError"; +import { type ReadStream, createReadStream, existsSync, readFileSync } from 'fs'; +import EnvironmentVariableParseError, { TargetedType } from '../Error/EnvironmentVariableParseError'; +import UndefinedEnvironmentVariableError from '../Error/UndefinedEnvironmentVariableError'; type ReadFileOptions = { flags?: string | undefined; @@ -102,13 +102,13 @@ class StringDictionaryReaderReadOnly { encoding: 'utf8', autoClose: true, emitClose: true, - ...options - } + ...options, + }, ); return new Promise((resolve, reject) => { stream.on('error', reject); - stream.on('open', () => { resolve(stream); }); + stream.on('open', () => resolve(stream)); }); } diff --git a/src/StringDictionaryReader/index.ts b/src/StringDictionaryReader/index.ts index c43bf91..7322f6c 100644 --- a/src/StringDictionaryReader/index.ts +++ b/src/StringDictionaryReader/index.ts @@ -1,4 +1,4 @@ -import StringDictionaryReaderReadOnly from "./ReadOnly"; +import StringDictionaryReaderReadOnly from './ReadOnly'; class StringDictionaryReader extends StringDictionaryReaderReadOnly { public constructor(dict: Record = {}) { diff --git a/src/index.ts b/src/index.ts index 086a4af..6e80669 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import Environment from "./Environment"; -import StringDictionaryReader from "./StringDictionaryReader"; -import StringDictionaryReaderReadOnly from "./StringDictionaryReader/ReadOnly"; +import Environment from './Environment'; +import StringDictionaryReader from './StringDictionaryReader'; +import StringDictionaryReaderReadOnly from './StringDictionaryReader/ReadOnly'; export default Environment; export { StringDictionaryReader, StringDictionaryReaderReadOnly }; diff --git a/yarn.lock b/yarn.lock index 6117fc8..0f8c78a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1952,6 +1952,22 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +eslint-plugin-autofix@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-autofix/-/eslint-plugin-autofix-1.1.0.tgz#157231b9e0f787e3d28e924da05cca46864960ce" + integrity sha512-aKQ7s6CTeJRJgnhSlsGI7kQhnNCa1q3UYBM+9PTEgvdC5b+GjV/SZA233VNqkoBldb7/BkeWBRjorUjxeUfrxA== + dependencies: + eslint-rule-composer "^0.3.0" + espree "^9.0.0" + esutils "^2.0.2" + lodash "^4.17.20" + string-similarity "^4.0.3" + +eslint-rule-composer@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz#79320c927b0c5c0d3d3d2b76c8b4a488f25bbaf9" + integrity sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg== + eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" @@ -2030,7 +2046,7 @@ eslint@^8.27.0: strip-json-comments "^3.1.0" text-table "^0.2.0" -espree@^9.4.0: +espree@^9.0.0, espree@^9.4.0: version "9.4.1" resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd" integrity sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg== @@ -2924,6 +2940,11 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash@^4.17.20: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" @@ -3414,6 +3435,11 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" +string-similarity@^4.0.3: + version "4.0.4" + resolved "https://registry.yarnpkg.com/string-similarity/-/string-similarity-4.0.4.tgz#42d01ab0b34660ea8a018da8f56a3309bb8b2a5b" + integrity sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ== + string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"