@diplodoc/lint 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +21 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/bin/lint +56 -0
- package/eslint-client-config.js +7 -0
- package/eslint-common-config.js +36 -0
- package/eslint-node-config.js +9 -0
- package/eslint-prettier-config.js +3 -0
- package/package.json +39 -0
- package/prettier-common-config.js +1 -0
- package/scaffolding/.eslintrc.js +8 -0
- package/scaffolding/.husky/pre-commit +4 -0
- package/scaffolding/.lintstagedrc.js +6 -0
- package/scaffolding/.prettierrc.js +1 -0
- package/scaffolding/.stylelintrc.js +3 -0
- package/scripts/modify-ignore.js +75 -0
- package/scripts/modify-package.js +27 -0
- package/stylelint-common-config.js +6 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
on:
|
|
2
|
+
push:
|
|
3
|
+
branches: [master]
|
|
4
|
+
|
|
5
|
+
name: release
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
pull-requests: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
release:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: gravity-ui/release-action@v1
|
|
16
|
+
with:
|
|
17
|
+
github-token: ${{ secrets.YC_UI_BOT_GITHUB_TOKEN }}
|
|
18
|
+
npm-token: ${{ secrets.ROBOT_DATAUI_NPM_TOKEN }}
|
|
19
|
+
node-version: 18
|
|
20
|
+
default-branch: ${{ github.ref_name != 'master' && github.ref_name || null }}
|
|
21
|
+
npm-dist-tag: ${{ github.ref_name != 'master' && 'untagged' || 'latest' }}
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Yandex LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[](https://www.npmjs.org/package/@diplodoc/lint)
|
|
2
|
+
|
|
3
|
+
# @diplodoc/lint
|
|
4
|
+
|
|
5
|
+
Diplodoc platform internal utility set for linting
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install --save-dev @diplodoc/lint
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Add initial configuration
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npx @diplodoc/lint install
|
|
20
|
+
git add --all && git commit -m 'chore: init lint'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Run lint
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm run lint
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Run lint in fix mode
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm run lint:fix
|
|
33
|
+
```
|
package/bin/lint
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
BINDIR=$(dirname $0)
|
|
6
|
+
SRCDIR=$(dirname $(dirname $(node -pe "require('fs').realpathSync('$0')")))
|
|
7
|
+
|
|
8
|
+
while (( $# )); do
|
|
9
|
+
case "$1" in
|
|
10
|
+
--fix ) :
|
|
11
|
+
FIX=1
|
|
12
|
+
;;
|
|
13
|
+
install|init ) :
|
|
14
|
+
INIT=1
|
|
15
|
+
;;
|
|
16
|
+
update ) :
|
|
17
|
+
UPDATE=1
|
|
18
|
+
;;
|
|
19
|
+
esac
|
|
20
|
+
shift
|
|
21
|
+
done
|
|
22
|
+
|
|
23
|
+
if [[ -n $INIT || -n $UPDATE]]; then
|
|
24
|
+
echo "[@diplodoc/lint] Add initial lint configs"
|
|
25
|
+
cp -r "$SRCDIR/scaffolding/" .
|
|
26
|
+
|
|
27
|
+
echo "[@diplodoc/lint] Extend .ignore configuration"
|
|
28
|
+
node "$SRCDIR/scripts/modify-ignore.js"
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if [[ -n $INIT ]]; then
|
|
32
|
+
echo "[@diplodoc/lint] Extend package.json configuration"
|
|
33
|
+
node "$SRCDIR/scripts/modify-package.js"
|
|
34
|
+
|
|
35
|
+
$BINDIR/husky install
|
|
36
|
+
|
|
37
|
+
exit 0
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
if [[ -n $FIX ]]; then
|
|
41
|
+
echo "Run linters in fix mode"
|
|
42
|
+
|
|
43
|
+
$BINDIR/eslint '**/*.{js,jsx,ts,tsx}' --fix
|
|
44
|
+
$BINDIR/prettier --write 'src/**/*.{js,jsx,ts,tsx}'
|
|
45
|
+
$BINDIR/stylelint src/**/*.scss --fix
|
|
46
|
+
|
|
47
|
+
exit 0
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
echo "Run linters"
|
|
51
|
+
|
|
52
|
+
$BINDIR/eslint '**/*.{js,jsx,ts,tsx}'
|
|
53
|
+
$BINDIR/prettier --check 'src/**/*.{js,jsx,ts,tsx}'
|
|
54
|
+
$BINDIR/stylelint src/**/*.scss
|
|
55
|
+
|
|
56
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
extends: [
|
|
4
|
+
'@gravity-ui/eslint-config',
|
|
5
|
+
process.env.npm_command && '@gravity-ui/eslint-config/prettier',
|
|
6
|
+
].filter(Boolean),
|
|
7
|
+
parserOptions: {
|
|
8
|
+
project: ["./tsconfig.json"]
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
'callback-return': 'off',
|
|
12
|
+
'consistent-return': 'off',
|
|
13
|
+
'no-implicit-globals': 'off',
|
|
14
|
+
'no-param-reassign': 'off',
|
|
15
|
+
'@typescript-eslint/no-shadow': 'off',
|
|
16
|
+
'import/no-extraneous-dependencies': 'error',
|
|
17
|
+
'import/order': [
|
|
18
|
+
'error',
|
|
19
|
+
{
|
|
20
|
+
alphabetize: {
|
|
21
|
+
order: 'ignore',
|
|
22
|
+
orderImportKind: 'asc'
|
|
23
|
+
},
|
|
24
|
+
'newlines-between': 'always',
|
|
25
|
+
groups: ['type', ['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'],
|
|
26
|
+
warnOnUnassignedImports: true,
|
|
27
|
+
pathGroups: [
|
|
28
|
+
{
|
|
29
|
+
pattern: '*.s?css$',
|
|
30
|
+
group: 'index',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diplodoc/lint",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Diplodoc platform internal utility set for linting",
|
|
5
|
+
"bin": {
|
|
6
|
+
"lint": "./bin/lint"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "exit 0"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
"./eslint-config": "./eslint-common-config.js",
|
|
13
|
+
"./eslint-config/client": "./eslint-client-config.js",
|
|
14
|
+
"./eslint-config/node": "./eslint-node-config.js",
|
|
15
|
+
"./eslint-config/prettier": "./eslint-client-config.js",
|
|
16
|
+
"./prettier-config": "./prettier-common-config.js",
|
|
17
|
+
"./stylelint-config": "./stylelint-common-config.js",
|
|
18
|
+
"./lintstaged-config": "./stylelint-common-config.js"
|
|
19
|
+
},
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@gravity-ui/eslint-config": "^3.2.0",
|
|
24
|
+
"@gravity-ui/prettier-config": "^1.1.0",
|
|
25
|
+
"@gravity-ui/stylelint-config": "^4.0.1",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^8.0.1",
|
|
27
|
+
"@typescript-eslint/parser": "^8.0.1",
|
|
28
|
+
"eslint": "^8.57.0",
|
|
29
|
+
"eslint-config-prettier": "^9.1.0",
|
|
30
|
+
"eslint-import-resolver-typescript": "^3.6.1",
|
|
31
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
32
|
+
"eslint-plugin-security": "^3.0.1",
|
|
33
|
+
"husky": "^9.1.4",
|
|
34
|
+
"lint-staged": "^15.2.8",
|
|
35
|
+
"prettier": "^3.3.3",
|
|
36
|
+
"stylelint": "15",
|
|
37
|
+
"svgo": "^3.3.2"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@gravity-ui/prettier-config');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@diplodoc/lint/prettier-config');
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const {readFileSync, writeFileSync} = require('fs');
|
|
2
|
+
|
|
3
|
+
const SYSTEM = [
|
|
4
|
+
'.idea',
|
|
5
|
+
'.vscode',
|
|
6
|
+
'.history',
|
|
7
|
+
'.env',
|
|
8
|
+
'.DS_Store',
|
|
9
|
+
];
|
|
10
|
+
const ARTIFACTS = [
|
|
11
|
+
'/lib',
|
|
12
|
+
'/dist',
|
|
13
|
+
'/build',
|
|
14
|
+
'/cache',
|
|
15
|
+
'/coverage',
|
|
16
|
+
];
|
|
17
|
+
const INSTALL = [
|
|
18
|
+
'node_modules',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const ignores = {
|
|
22
|
+
'.gitignore': [
|
|
23
|
+
...SYSTEM,
|
|
24
|
+
...INSTALL,
|
|
25
|
+
...ARTIFACTS,
|
|
26
|
+
'/.eslintrc.js',
|
|
27
|
+
'/.prettierrc.js',
|
|
28
|
+
'/.stylelintrc.js',
|
|
29
|
+
'/.lintstagedrc.js',
|
|
30
|
+
// '/.eslinignore',
|
|
31
|
+
// '/.prettierignore',
|
|
32
|
+
// '/.stylelintignore',
|
|
33
|
+
],
|
|
34
|
+
'.eslintignore': [
|
|
35
|
+
...SYSTEM,
|
|
36
|
+
...INSTALL,
|
|
37
|
+
...ARTIFACTS,
|
|
38
|
+
],
|
|
39
|
+
'.prettierignore': [
|
|
40
|
+
...SYSTEM,
|
|
41
|
+
...INSTALL,
|
|
42
|
+
...ARTIFACTS,
|
|
43
|
+
],
|
|
44
|
+
'.stylelintignore': [
|
|
45
|
+
...SYSTEM,
|
|
46
|
+
...INSTALL,
|
|
47
|
+
...ARTIFACTS,
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
for (const [file, list] of Object.entries(ignores)) {
|
|
52
|
+
const filename = process.cwd() + '/' + file;
|
|
53
|
+
|
|
54
|
+
let source;
|
|
55
|
+
try {
|
|
56
|
+
source = readFileSync(filename, 'utf8').split('\n');
|
|
57
|
+
} catch {
|
|
58
|
+
source = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.log('[@diplodoc/lint]', 'Update', file);
|
|
62
|
+
|
|
63
|
+
for (const rule of list) {
|
|
64
|
+
add(source, rule);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
writeFileSync(filename, source.join('\n'), 'utf8');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function add(source, ignore) {
|
|
71
|
+
if (!source.includes(ignore)) {
|
|
72
|
+
source.push(ignore);
|
|
73
|
+
console.log('[@diplodoc/lint]', '=> Add', ignore);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const filename = process.cwd() + '/package.json';
|
|
2
|
+
const {readFileSync, writeFileSync} = require('fs');
|
|
3
|
+
|
|
4
|
+
let pkg;
|
|
5
|
+
try {
|
|
6
|
+
pkg = JSON.parse(readFileSync(filename));
|
|
7
|
+
} catch {
|
|
8
|
+
throw 'Unable to modify ' + filename;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function configure(command, impl) {
|
|
12
|
+
if (pkg.scripts[command]) {
|
|
13
|
+
if (pkg.scripts[command] !== impl) {
|
|
14
|
+
throw `Lint command '${command}' already configured with different program`;
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
pkg.scripts[command] = impl;
|
|
18
|
+
console.log('=> Add', command, 'script');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
configure('lint', 'lint init && lint');
|
|
23
|
+
configure('lint:fix', 'lint init && lint --fix');
|
|
24
|
+
configure('pre-commit', 'lint init && lint-staged');
|
|
25
|
+
configure('prepare', 'husky install || true');
|
|
26
|
+
|
|
27
|
+
writeFileSync(filename, JSON.stringify(pkg, null, 2), 'utf8');
|