From 89ee0b7f681206dae9ed75d9d1257284783091af Mon Sep 17 00:00:00 2001 From: Andrij Orlenko <94047334+lotyp@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:24:24 +0200 Subject: [PATCH] ci: linting (#4) * ci: disable lint temporarly * ci: disable npm cache * ci: add pnpm cache * ci: add cache dir * feat: add changesets * fix: wrong version for dep * feat: add linting action task --- .github/workflows/ci.yml | 2 +- .markdownlintignore | 4 + package.json | 2 +- .../commitizen-config/scripts/postinstall.js | 10 +-- packages/commitlint-config/index.js | 14 +-- .../commitlint-config/scripts/postinstall.js | 10 +-- packages/eslint-config/index.js | 80 ++++++++--------- packages/eslint-config/jest.js | 12 +-- packages/eslint-config/scripts/postinstall.js | 10 +-- packages/eslint-config/ts.js | 88 +++++++++---------- packages/lint-staged-config/index.js | 2 +- .../lint-staged-config/scripts/postinstall.js | 8 +- packages/lint-staged-config/yml.js | 4 +- .../scripts/postinstall.js | 10 +-- packages/prettier-config/index.js | 42 ++++----- packages/secretlint-config/index.json | 10 +-- .../secretlint-config/scripts/postinstall.js | 8 +- 17 files changed, 160 insertions(+), 156 deletions(-) create mode 100644 .markdownlintignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2669ae5e..3116a62c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: uses: actions/cache@v3 with: path: node_modules - key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} + key: pnpm-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} - name: Install frontend dependencies if: steps.cached-pnpm-dependencies.outputs.cache-hit != 'true' diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 00000000..e072bda8 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,4 @@ +node_modules/ +CHANGELOG.md +**/node_modules/ +**/CHANGELOG.md diff --git a/package.json b/package.json index 640848ff..51b448f4 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "prepare": "husky install", "lint": "pnpm run lint:md && pnpm run lint:js && pnpm run lint:secrets", - "lint:md": "markdownlint --fix **/*.md --ignore node_modules --ignore **/CHANGELOG.md", + "lint:md": "markdownlint --fix **/*.md", "lint:js": "eslint --fix **/*.js", "lint:secrets": "secretlint **/*" }, diff --git a/packages/commitizen-config/scripts/postinstall.js b/packages/commitizen-config/scripts/postinstall.js index 0040cc30..cf89b73c 100644 --- a/packages/commitizen-config/scripts/postinstall.js +++ b/packages/commitizen-config/scripts/postinstall.js @@ -5,12 +5,12 @@ const path = require('node:path'); const filePath = path.join(process.env.INIT_CWD, '.czrc'); const fileConfigObject = { - path: 'cz-conventional-changelog', + path: 'cz-conventional-changelog', }; if (!fs.existsSync(filePath)) { - fs.writeFileSync( - filePath, - `${JSON.stringify(fileConfigObject, undefined, 2)}` - ); + fs.writeFileSync( + filePath, + `${JSON.stringify(fileConfigObject, undefined, 2)}` + ); } diff --git a/packages/commitlint-config/index.js b/packages/commitlint-config/index.js index 4ba25a68..06e1c978 100644 --- a/packages/commitlint-config/index.js +++ b/packages/commitlint-config/index.js @@ -1,11 +1,11 @@ const automaticCommitPattern = /^chore\(release\):.*\[skip ci]/; module.exports = { - extends: ['@commitlint/config-conventional'], - /* - This resolves a linting conflict between commitlint's body-max-line-length - due to @semantic-release/git putting release notes in the commit body - https://github.com/semantic-release/git/issues/331 - */ - ignores: [commitMessage => automaticCommitPattern.test(commitMessage)], + extends: ['@commitlint/config-conventional'], + /* + This resolves a linting conflict between commitlint's body-max-line-length + due to @semantic-release/git putting release notes in the commit body + https://github.com/semantic-release/git/issues/331 + */ + ignores: [commitMessage => automaticCommitPattern.test(commitMessage)], }; diff --git a/packages/commitlint-config/scripts/postinstall.js b/packages/commitlint-config/scripts/postinstall.js index 808bd34b..4c50ac13 100644 --- a/packages/commitlint-config/scripts/postinstall.js +++ b/packages/commitlint-config/scripts/postinstall.js @@ -5,12 +5,12 @@ const path = require('node:path'); const filePath = path.join(process.env.INIT_CWD, 'commitlint.config.js'); const fileConfigObject = { - extends: '@wayofdev/commitlint-config', + extends: '@wayofdev/commitlint-config', }; if (!fs.existsSync(filePath)) { - fs.writeFileSync( - filePath, - `module.exports = ${JSON.stringify(fileConfigObject, undefined, 2)}` - ); + fs.writeFileSync( + filePath, + `module.exports = ${JSON.stringify(fileConfigObject, undefined, 2)}` + ); } diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index 10b5ffe5..eed92f87 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -1,43 +1,43 @@ module.exports = { - // Plugins that provide the processors to parse code for linting - plugins: ['sonarjs', 'prettier'], - extends: [ - 'plugin:unicorn/recommended', - 'plugin:promise/recommended', - 'plugin:sonarjs/recommended', - 'plugin:security/recommended', - // Uses the recommended rules from eslint - 'eslint:recommended', - /* - Uses the recommended rules from eslint-config-airbnb-base - Note: depends on eslint-plugin-import to work - */ - 'airbnb-base', - /* - Enables eslint-plugin-prettier and displays prettier errors as - ESLint errors. Make sure this is always the last configuration - in the extends array. - https://github.com/prettier/eslint-plugin-prettier#recommended-configuration - */ - 'plugin:prettier/recommended', - ], - // @babel/eslint-parser and prettier rules go here - rules: { - // https://github.com/prettier/eslint-config-prettier#max-len - 'max-len': [ - 'error', - { - code: 80, - ignoreUrls: true, - }, + // Plugins that provide the processors to parse code for linting + plugins: ['sonarjs', 'prettier'], + extends: [ + 'plugin:unicorn/recommended', + 'plugin:promise/recommended', + 'plugin:sonarjs/recommended', + 'plugin:security/recommended', + // Uses the recommended rules from eslint + 'eslint:recommended', + /* + Uses the recommended rules from eslint-config-airbnb-base + Note: depends on eslint-plugin-import to work + */ + 'airbnb-base', + /* + Enables eslint-plugin-prettier and displays prettier errors as + ESLint errors. Make sure this is always the last configuration + in the extends array. + https://github.com/prettier/eslint-plugin-prettier#recommended-configuration + */ + 'plugin:prettier/recommended', ], - // https://stackoverflow.com/questions/44939304/eslint-should-be-listed-in-the-projects-dependencies-not-devdependencies - 'import/no-extraneous-dependencies': [ - 'error', - { - devDependencies: true, - }, - ], - 'unicorn/prefer-module': 0, - }, + // @babel/eslint-parser and prettier rules go here + rules: { + // https://github.com/prettier/eslint-config-prettier#max-len + 'max-len': [ + 'error', + { + code: 80, + ignoreUrls: true, + }, + ], + // https://stackoverflow.com/questions/44939304/eslint-should-be-listed-in-the-projects-dependencies-not-devdependencies + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: true, + }, + ], + 'unicorn/prefer-module': 0, + }, }; diff --git a/packages/eslint-config/jest.js b/packages/eslint-config/jest.js index 029ae78f..db3c5a42 100644 --- a/packages/eslint-config/jest.js +++ b/packages/eslint-config/jest.js @@ -1,8 +1,8 @@ module.exports = { - plugins: ['jest', 'jest-dom', 'jest-formatting'], - extends: [ - 'plugin:jest/recommended', - 'plugin:jest-dom/recommended', - 'plugin:jest-formatting/recommended', - ], + plugins: ['jest', 'jest-dom', 'jest-formatting'], + extends: [ + 'plugin:jest/recommended', + 'plugin:jest-dom/recommended', + 'plugin:jest-formatting/recommended', + ], }; diff --git a/packages/eslint-config/scripts/postinstall.js b/packages/eslint-config/scripts/postinstall.js index 301bc746..d4c66ad8 100644 --- a/packages/eslint-config/scripts/postinstall.js +++ b/packages/eslint-config/scripts/postinstall.js @@ -5,12 +5,12 @@ const path = require('node:path'); const filePath = path.join(process.env.INIT_CWD, '.eslintrc.js'); const fileConfigObject = { - extends: '@wayofdev/eslint-config', + extends: '@wayofdev/eslint-config', }; if (!fs.existsSync(filePath)) { - fs.writeFileSync( - filePath, - `module.exports = ${JSON.stringify(fileConfigObject, undefined, 2)}` - ); + fs.writeFileSync( + filePath, + `module.exports = ${JSON.stringify(fileConfigObject, undefined, 2)}` + ); } diff --git a/packages/eslint-config/ts.js b/packages/eslint-config/ts.js index 3c46260d..92282a27 100644 --- a/packages/eslint-config/ts.js +++ b/packages/eslint-config/ts.js @@ -1,49 +1,49 @@ module.exports = { - // Plugins that provide the processors to parse code for linting - plugins: ['sonarjs', '@typescript-eslint', 'prettier'], - /* - A parser that converts TypeScript into an ESTree-compatible - form so it can be used in ESLint. - */ - parser: '@typescript-eslint/parser', - extends: [ - 'plugin:unicorn/recommended', - 'plugin:promise/recommended', - 'plugin:sonarjs/recommended', - 'plugin:security/recommended', - // Uses the recommended rules from the @typescript-eslint/eslint-plugin - 'plugin:@typescript-eslint/recommended', + // Plugins that provide the processors to parse code for linting + plugins: ['sonarjs', '@typescript-eslint', 'prettier'], /* - Uses the recommended rules from eslint-config-airbnb-typescript - depends on @typescript-eslint/eslint-plugin - and eslint-plugin-import to work + A parser that converts TypeScript into an ESTree-compatible + form so it can be used in ESLint. */ - 'airbnb-typescript/base', - /* - Enables eslint-plugin-prettier and displays prettier errors as - ESLint errors. Make sure this is always the last configuration - in the extends array. - https://github.com/prettier/eslint-plugin-prettier#recommended-configuration - */ - 'plugin:prettier/recommended', - ], - // @typescript-eslint/parser and prettier rules go here - rules: { - // https://github.com/prettier/eslint-config-prettier#max-len - 'max-len': [ - 'error', - { - code: 80, - ignoreUrls: true, - }, - ], - // https://stackoverflow.com/questions/44939304/eslint-should-be-listed-in-the-projects-dependencies-not-devdependencies - 'import/no-extraneous-dependencies': [ - 'error', - { - devDependencies: true, - }, + parser: '@typescript-eslint/parser', + extends: [ + 'plugin:unicorn/recommended', + 'plugin:promise/recommended', + 'plugin:sonarjs/recommended', + 'plugin:security/recommended', + // Uses the recommended rules from the @typescript-eslint/eslint-plugin + 'plugin:@typescript-eslint/recommended', + /* + Uses the recommended rules from eslint-config-airbnb-typescript + depends on @typescript-eslint/eslint-plugin + and eslint-plugin-import to work + */ + 'airbnb-typescript/base', + /* + Enables eslint-plugin-prettier and displays prettier errors as + ESLint errors. Make sure this is always the last configuration + in the extends array. + https://github.com/prettier/eslint-plugin-prettier#recommended-configuration + */ + 'plugin:prettier/recommended', ], - 'unicorn/prefer-module': 0, - }, + // @typescript-eslint/parser and prettier rules go here + rules: { + // https://github.com/prettier/eslint-config-prettier#max-len + 'max-len': [ + 'error', + { + code: 80, + ignoreUrls: true, + }, + ], + // https://stackoverflow.com/questions/44939304/eslint-should-be-listed-in-the-projects-dependencies-not-devdependencies + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: true, + }, + ], + 'unicorn/prefer-module': 0, + }, }; diff --git a/packages/lint-staged-config/index.js b/packages/lint-staged-config/index.js index f0d18ec5..23841290 100644 --- a/packages/lint-staged-config/index.js +++ b/packages/lint-staged-config/index.js @@ -1,4 +1,4 @@ /* eslint-disable sonarjs/no-duplicate-string */ module.exports = { - '*.{js,jsx,ts,tsx}': ['prettier --cache --write', 'eslint --cache --fix'], + '*.{js,jsx,ts,tsx}': ['prettier --cache --write', 'eslint --cache --fix'], }; diff --git a/packages/lint-staged-config/scripts/postinstall.js b/packages/lint-staged-config/scripts/postinstall.js index 5ea7ea75..8674fd1c 100644 --- a/packages/lint-staged-config/scripts/postinstall.js +++ b/packages/lint-staged-config/scripts/postinstall.js @@ -5,8 +5,8 @@ const path = require('node:path'); const filePath = path.join(process.env.INIT_CWD, 'lint-staged.config.js'); if (!fs.existsSync(filePath)) { - fs.writeFileSync( - filePath, - `module.exports = require('@wayofdev/lint-staged-config');` - ); + fs.writeFileSync( + filePath, + `module.exports = require('@wayofdev/lint-staged-config');` + ); } diff --git a/packages/lint-staged-config/yml.js b/packages/lint-staged-config/yml.js index d5b90ee9..79e5e8c7 100644 --- a/packages/lint-staged-config/yml.js +++ b/packages/lint-staged-config/yml.js @@ -1,4 +1,4 @@ module.exports = { - '*.{yml,yaml}': ['prettier --cache --write', 'yamllint --strict .'], - '.github/workflows/*.{yml,yaml}': ['actionlint'], + '*.{yml,yaml}': ['prettier --cache --write', 'yamllint --strict .'], + '.github/workflows/*.{yml,yaml}': ['actionlint'], }; diff --git a/packages/markdownlint-config/scripts/postinstall.js b/packages/markdownlint-config/scripts/postinstall.js index 73b21f5b..ad91068e 100644 --- a/packages/markdownlint-config/scripts/postinstall.js +++ b/packages/markdownlint-config/scripts/postinstall.js @@ -5,12 +5,12 @@ const path = require('node:path'); const filePath = path.join(process.env.INIT_CWD, '.markdownlint.json'); const fileConfigObject = { - extends: './node_modules/@wayofdev/markdownlint-config/index.json', + extends: './node_modules/@wayofdev/markdownlint-config/index.json', }; if (!fs.existsSync(filePath)) { - fs.writeFileSync( - filePath, - `${JSON.stringify(fileConfigObject, undefined, 2)}` - ); + fs.writeFileSync( + filePath, + `${JSON.stringify(fileConfigObject, undefined, 2)}` + ); } diff --git a/packages/prettier-config/index.js b/packages/prettier-config/index.js index f0e5d7db..5da525fd 100644 --- a/packages/prettier-config/index.js +++ b/packages/prettier-config/index.js @@ -1,23 +1,23 @@ module.exports = { - endOfLine: 'auto', - // https://prettier.io/docs/en/options.html#print-width - printWidth: 80, - tabWidth: 2, - arrowParens: 'avoid', - singleQuote: true, - semi: true, - trailingComma: 'es5', - bracketSpacing: true, - overrides: [ - { - files: ['*.html'], - options: { - // disable to prevent conflicts with html-validate - trailingComma: 'none', - // https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting - htmlWhitespaceSensitivity: 'css', - singleAttributePerLine: true, - }, - }, - ], + endOfLine: 'auto', + // https://prettier.io/docs/en/options.html#print-width + printWidth: 80, + tabWidth: 2, + arrowParens: 'avoid', + singleQuote: true, + semi: true, + trailingComma: 'es5', + bracketSpacing: true, + overrides: [ + { + files: ['*.html'], + options: { + // disable to prevent conflicts with html-validate + trailingComma: 'none', + // https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting + htmlWhitespaceSensitivity: 'css', + singleAttributePerLine: true, + }, + }, + ], }; diff --git a/packages/secretlint-config/index.json b/packages/secretlint-config/index.json index 7a1a5df3..18c4bb41 100644 --- a/packages/secretlint-config/index.json +++ b/packages/secretlint-config/index.json @@ -1,7 +1,7 @@ { - "rules": [ - { - "id": "@secretlint/secretlint-rule-preset-recommend" - } - ] + "rules": [ + { + "id": "@secretlint/secretlint-rule-preset-recommend" + } + ] } diff --git a/packages/secretlint-config/scripts/postinstall.js b/packages/secretlint-config/scripts/postinstall.js index 2d09b60c..848ab8d8 100644 --- a/packages/secretlint-config/scripts/postinstall.js +++ b/packages/secretlint-config/scripts/postinstall.js @@ -5,8 +5,8 @@ const path = require('node:path'); const filePath = path.join(process.env.INIT_CWD, '.secretlintrc.js'); if (!fs.existsSync(filePath)) { - fs.writeFileSync( - filePath, - `module.exports = { ...require('@wayofdev/secretlint-config') };` - ); + fs.writeFileSync( + filePath, + `module.exports = { ...require('@wayofdev/secretlint-config') };` + ); }