From 3750e54a17e8502846202e2c6bfc0501f826a71d Mon Sep 17 00:00:00 2001 From: Clemens Grabmann Date: Thu, 21 Oct 2021 12:26:37 +0200 Subject: [PATCH] * add cloudflight typescript rules * add license --- .eslintignore | 3 +- .eslintrc.js | 14 +- .gitignore | 3 +- .prettierignore | 4 + LICENSE | 7 + lerna.json | 2 +- package-lock.json | 159 +++++---------- package.json | 8 +- .../eslint-plugin-typescript/package.json | 4 +- .../src/configs/index.ts | 2 +- .../src/configs/recommended.config.ts | 14 -- .../configs/recommended/recommended.config.ts | 185 ++++++++++++++++++ scripts/copy-license/copy-license.js | 26 +++ scripts/prepare.js | 3 + 14 files changed, 293 insertions(+), 141 deletions(-) create mode 100644 .prettierignore create mode 100644 LICENSE delete mode 100644 packages/eslint-plugin-typescript/src/configs/recommended.config.ts create mode 100644 packages/eslint-plugin-typescript/src/configs/recommended/recommended.config.ts create mode 100644 scripts/copy-license/copy-license.js create mode 100644 scripts/prepare.js diff --git a/.eslintignore b/.eslintignore index 7c7fd94..a5f66cc 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ -dist/ +**/dist/ node_modules/ .eslintrc.js +.git/ diff --git a/.eslintrc.js b/.eslintrc.js index 7010eb5..5ac48b8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,13 +1,21 @@ module.exports = { root: true, - plugins: ['@cloudflight/typescript', 'eslint-plugin'], + plugins: ['@cloudflight/typescript'], env: { es6: true, node: true, }, - extends: ['plugin:@cloudflight/typescript/recommended'], parserOptions: { - project: ['./packages/*/tsconfig.json'], + sourceType: 'module', tsconfigRootDir: __dirname, }, + overrides: [ + { + files: ['*.ts'], + extends: ['plugin:@cloudflight/typescript/recommended'], + parserOptions: { + project: ['./packages/*/tsconfig.json'], + }, + }, + ], }; diff --git a/.gitignore b/.gitignore index 8921995..f2a3eb4 100644 --- a/.gitignore +++ b/.gitignore @@ -234,5 +234,6 @@ dist # End of https://www.toptal.com/developers/gitignore/api/node,intellij -dist/ +**/dist/ .idea/ +packages/**/LICENSE diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..bad96a1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +.idea +node_modules +.git/ +**/dist/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7707611 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2021 Cloudflight GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lerna.json b/lerna.json index 12b694e..acfbcc1 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "packages": ["packages/*"], - "version": "1.0.0", + "version": "0.1.0", "npmClient": "npm", "useWorkspaces": true } diff --git a/package-lock.json b/package-lock.json index 6e4adc1..535c902 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,14 @@ { "name": "@cloudflight/cleancode-eslint-plugin", - "version": "1.0.0", + "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@cloudflight/cleancode-eslint-plugin", - "version": "1.0.0", + "version": "0.1.0", "hasInstallScript": true, - "license": "ISC", + "license": "MIT", "workspaces": [ "packages/*" ], @@ -19,7 +19,6 @@ "@typescript-eslint/eslint-plugin": "5.1.0", "@typescript-eslint/parser": "5.1.0", "eslint": "8.0.0", - "eslint-plugin-eslint-plugin": "4.0.1", "husky": "7.0.2", "lerna": "^4.0.0", "prettier": "2.4.1", @@ -1604,7 +1603,22 @@ } } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/experimental-utils": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, + "node_modules/@typescript-eslint/experimental-utils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.1.0.tgz", "integrity": "sha512-ovE9qUiZMOMgxQAESZsdBT+EXIfx/YUYAbwGUI6V03amFdOOxI9c6kitkgRvLkJaLusgMZ2xBhss+tQ0Y1HWxA==", @@ -1628,25 +1642,7 @@ "eslint": "*" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/experimental-utils/node_modules/eslint-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", - "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", - "dev": true, - "dependencies": { - "eslint-visitor-keys": "^2.0.0" - }, - "engines": { - "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/mysticatea" - }, - "peerDependencies": { - "eslint": ">=5" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/eslint-scope": { + "node_modules/@typescript-eslint/experimental-utils/node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", @@ -1659,16 +1655,7 @@ "node": ">=8.0.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/eslint-visitor-keys": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", - "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/estraverse": { + "node_modules/@typescript-eslint/experimental-utils/node_modules/estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", @@ -1677,21 +1664,6 @@ "node": ">=4.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, "node_modules/@typescript-eslint/parser": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.1.0.tgz", @@ -3121,22 +3093,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint-plugin-eslint-plugin": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-4.0.1.tgz", - "integrity": "sha512-ey21uE/uOanYAWakWNeFDXF4MEySczTyhdxbKYs5SCTa89MH5Z/TOZ/ui8OqSsAC+QR49iKNuh5kvVSoZhdc7Q==", - "dev": true, - "dependencies": { - "eslint-utils": "^3.0.0", - "estraverse": "^5.2.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "peerDependencies": { - "eslint": ">=6.0.0" - } - }, "node_modules/eslint-scope": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-6.0.0.tgz", @@ -8290,8 +8246,8 @@ }, "packages/eslint-plugin-typescript": { "name": "@cloudflight/eslint-plugin-typescript", - "version": "1.0.0", - "license": "ISC", + "version": "0.1.0", + "license": "MIT", "devDependencies": { "@types/eslint": "7.28.1", "@types/estree": "0.0.50", @@ -9623,31 +9579,31 @@ "tsutils": "^3.21.0" }, "dependencies": { - "@typescript-eslint/experimental-utils": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.1.0.tgz", - "integrity": "sha512-ovE9qUiZMOMgxQAESZsdBT+EXIfx/YUYAbwGUI6V03amFdOOxI9c6kitkgRvLkJaLusgMZ2xBhss+tQ0Y1HWxA==", + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", "dev": true, "requires": { - "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.1.0", - "@typescript-eslint/types": "5.1.0", - "@typescript-eslint/typescript-estree": "5.1.0", - "eslint-scope": "^5.1.1", - "eslint-utils": "^3.0.0" - }, - "dependencies": { - "eslint-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", - "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", - "dev": true, - "requires": { - "eslint-visitor-keys": "^2.0.0" - } - } + "tslib": "^1.8.1" } - }, + } + } + }, + "@typescript-eslint/experimental-utils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.1.0.tgz", + "integrity": "sha512-ovE9qUiZMOMgxQAESZsdBT+EXIfx/YUYAbwGUI6V03amFdOOxI9c6kitkgRvLkJaLusgMZ2xBhss+tQ0Y1HWxA==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.9", + "@typescript-eslint/scope-manager": "5.1.0", + "@typescript-eslint/types": "5.1.0", + "@typescript-eslint/typescript-estree": "5.1.0", + "eslint-scope": "^5.1.1", + "eslint-utils": "^3.0.0" + }, + "dependencies": { "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -9658,26 +9614,11 @@ "estraverse": "^4.1.1" } }, - "eslint-visitor-keys": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", - "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", - "dev": true - }, "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true - }, - "tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } } } }, @@ -10818,16 +10759,6 @@ } } }, - "eslint-plugin-eslint-plugin": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-4.0.1.tgz", - "integrity": "sha512-ey21uE/uOanYAWakWNeFDXF4MEySczTyhdxbKYs5SCTa89MH5Z/TOZ/ui8OqSsAC+QR49iKNuh5kvVSoZhdc7Q==", - "dev": true, - "requires": { - "eslint-utils": "^3.0.0", - "estraverse": "^5.2.0" - } - }, "eslint-scope": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-6.0.0.tgz", diff --git a/package.json b/package.json index aa8e74e..6cef298 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/cleancode-eslint-plugin", - "version": "1.0.0", + "version": "0.1.0", "private": true, "workspaces": [ "packages/*" @@ -12,14 +12,15 @@ "scripts": { "build": "lerna run build", "lint": "eslint .", - "postinstall": "npm run build" + "postinstall": "npm run build", + "prepare": "node ./scripts/prepare.js" }, "keywords": [ "eslint", "eslintplugin" ], "author": "Cloudflight GmbH", - "license": "ISC", + "license": "MIT", "devDependencies": { "@types/eslint": "7.28.1", "@types/estree": "0.0.50", @@ -27,7 +28,6 @@ "@typescript-eslint/eslint-plugin": "5.1.0", "@typescript-eslint/parser": "5.1.0", "eslint": "8.0.0", - "eslint-plugin-eslint-plugin": "4.0.1", "husky": "7.0.2", "lerna": "^4.0.0", "prettier": "2.4.1", diff --git a/packages/eslint-plugin-typescript/package.json b/packages/eslint-plugin-typescript/package.json index 7fe0db4..b0c2e10 100644 --- a/packages/eslint-plugin-typescript/package.json +++ b/packages/eslint-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin-typescript", - "version": "1.0.0", + "version": "0.1.0", "description": "Cloudflight cleancode eslint plugin for typescript", "keywords": [ "eslint", @@ -8,7 +8,7 @@ ], "homepage": "", "author": "Cloudflight GmbH", - "license": "ISC", + "license": "MIT", "main": "./dist/index.js", "files": [ "dist/**" diff --git a/packages/eslint-plugin-typescript/src/configs/index.ts b/packages/eslint-plugin-typescript/src/configs/index.ts index 29d6be8..ab79ada 100644 --- a/packages/eslint-plugin-typescript/src/configs/index.ts +++ b/packages/eslint-plugin-typescript/src/configs/index.ts @@ -1,4 +1,4 @@ -import { RecommendedConfig } from './recommended.config'; +import { RecommendedConfig } from './recommended/recommended.config'; import { Linter } from 'eslint'; export const configs: Record = { diff --git a/packages/eslint-plugin-typescript/src/configs/recommended.config.ts b/packages/eslint-plugin-typescript/src/configs/recommended.config.ts deleted file mode 100644 index c54fae2..0000000 --- a/packages/eslint-plugin-typescript/src/configs/recommended.config.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Linter } from 'eslint'; - -export const RecommendedConfig: Linter.BaseConfig = { - plugins: ['@cloudflight/typescript'], - parser: '@typescript-eslint/parser', - overrides: [ - { - files: ['*.ts'], - rules: { - '@cloudflight/typescript/test-rule': 'warn', - }, - }, - ], -}; diff --git a/packages/eslint-plugin-typescript/src/configs/recommended/recommended.config.ts b/packages/eslint-plugin-typescript/src/configs/recommended/recommended.config.ts new file mode 100644 index 0000000..654270f --- /dev/null +++ b/packages/eslint-plugin-typescript/src/configs/recommended/recommended.config.ts @@ -0,0 +1,185 @@ +import { Linter } from 'eslint'; + +export const RecommendedConfig: Linter.BaseConfig = { + plugins: ['@cloudflight/typescript', '@typescript-eslint'], + parser: '@typescript-eslint/parser', + rules: { + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/ban-types': [ + 'error', + { + types: { + Object: { + message: 'Avoid using the `Object` type. Did you mean `object`?', + }, + Function: { + message: 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.', + }, + Boolean: { + message: 'Avoid using the `Boolean` type. Did you mean `boolean`?', + }, + Number: { + message: 'Avoid using the `Number` type. Did you mean `number`?', + }, + String: { + message: 'Avoid using the `String` type. Did you mean `string`?', + }, + Symbol: { + message: 'Avoid using the `Symbol` type. Did you mean `symbol`?', + }, + }, + }, + ], + '@typescript-eslint/member-ordering': [ + 'error', + { + default: [ + 'signature', + 'public-abstract-field', + 'protected-abstract-field', + 'private-abstract-field', + 'public-static-field', + 'protected-static-field', + 'private-static-field', + 'public-decorated-field', + 'protected-decorated-field', + 'private-decorated-field', + 'public-instance-field', + 'protected-instance-field', + 'private-instance-field', + 'public-constructor', + 'protected-constructor', + 'private-constructor', + 'public-abstract-method', + 'protected-abstract-method', + 'private-abstract-method', + 'public-static-method', + 'protected-static-method', + 'private-static-method', + 'public-decorated-method', + 'protected-decorated-method', + 'private-decorated-method', + 'public-instance-method', + 'protected-instance-method', + 'private-instance-method', + ], + }, + ], + '@typescript-eslint/no-empty-interface': 'error', + '@typescript-eslint/no-inferrable-types': [ + 'error', + { + ignoreParameters: true, + }, + ], + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-namespace': 'error', + '@typescript-eslint/no-non-null-assertion': 'error', + '@typescript-eslint/no-unused-expressions': 'error', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/prefer-for-of': 'error', + '@typescript-eslint/unified-signatures': 'error', + 'constructor-super': 'error', + 'no-bitwise': 'error', + 'no-console': 'error', + 'no-debugger': 'error', + 'no-eval': 'error', + 'no-fallthrough': 'error', + 'no-restricted-imports': [ + 'error', + { + name: 'rxjs/Rx', + message: "Please import directly from 'rxjs' instead", + }, + ], + 'no-shadow': 'off', + '@typescript-eslint/no-shadow': 'error', + 'no-throw-literal': 'error', + 'no-unsafe-finally': 'error', + 'no-unused-labels': 'error', + 'no-var': 'error', + 'object-shorthand': 'error', + 'prefer-const': 'error', + radix: 'error', + 'use-isnan': 'error', + curly: 'error', + 'eol-last': 'error', + 'new-parens': 'error', + 'no-multiple-empty-lines': 'off', + 'no-trailing-spaces': 'error', + 'space-before-function-paren': [ + 'error', + { + anonymous: 'never', + asyncArrow: 'always', + named: 'never', + }, + ], + '@typescript-eslint/member-delimiter-style': [ + 'error', + { + multiline: { + delimiter: 'semi', + requireLast: true, + }, + singleline: { + delimiter: 'semi', + requireLast: false, + }, + }, + ], + quotes: 'off', + '@typescript-eslint/quotes': [ + 'error', + 'single', + { + avoidEscape: true, + allowTemplateLiterals: true, + }, + ], + '@typescript-eslint/semi': ['error', 'always'], + '@typescript-eslint/type-annotation-spacing': 'error', + '@typescript-eslint/array-type': [ + 'error', + { + default: 'array', + }, + ], + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/ban-ts-comment': 'error', + '@typescript-eslint/explicit-member-accessibility': [ + 'error', + { + accessibility: 'explicit', + }, + ], + '@typescript-eslint/no-empty-function': 'error', + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-for-in-array': 'error', + 'no-param-reassign': ['error'], + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/promise-function-async': 'error', + complexity: [ + 'error', + { + max: 20, + }, + ], + 'import/no-unassigned-import': 'off', + 'max-classes-per-file': ['error', 1], + 'max-len': [ + 'error', + { + ignorePattern: '^import [^,]+ from', + code: 140, + }, + ], + 'no-empty': 'error', + 'no-invalid-this': 'error', + 'no-new-func': 'error', + 'no-restricted-syntax': ['error', 'ForInStatement'], + 'no-sequences': 'error', + 'quote-props': ['error', 'as-needed'], + }, +}; diff --git a/scripts/copy-license/copy-license.js b/scripts/copy-license/copy-license.js new file mode 100644 index 0000000..4622945 --- /dev/null +++ b/scripts/copy-license/copy-license.js @@ -0,0 +1,26 @@ +const fs = require('fs'); +const path = require('path'); + +const licenseFileName = 'LICENSE'; +const rootDir = path.normalize(`${__dirname}/../../`); +const packagesDir = path.join(rootDir, 'packages'); +const rootLicenseFile = path.join(rootDir, licenseFileName); + +function isNpmPackage(path) { + const files = fs.readdirSync(path); + return files.some((fileName) => fileName === 'package.json'); +} + +module.exports = { + copyLicenses() { + const packages = fs.readdirSync(packagesDir); + for (const packageDirName of packages) { + const packagePath = path.join(packagesDir, packageDirName); + const packageStat = fs.statSync(packagePath); + if (packageStat.isDirectory() && isNpmPackage(packagePath)) { + const packageLicenseFile = path.join(packagePath, licenseFileName); + fs.copyFileSync(rootLicenseFile, packageLicenseFile); + } + } + }, +}; diff --git a/scripts/prepare.js b/scripts/prepare.js new file mode 100644 index 0000000..82ea3b9 --- /dev/null +++ b/scripts/prepare.js @@ -0,0 +1,3 @@ +const copyLicenses = require('./copy-license/copy-license').copyLicenses; + +copyLicenses();