@kitql/eslint-config 0.0.3 → 0.1.0-next.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/README.md +8 -9
- package/cmd.js +57 -52
- package/index.cjs +3 -3
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@kitql/eslint-config)
|
|
4
4
|
[](https://www.npmjs.com/package/@kitql/eslint-config)
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## 📖 Read the doc
|
|
7
7
|
|
|
8
8
|
[](https://kitql.dev/docs)
|
|
9
9
|
|
|
@@ -16,25 +16,24 @@ npm install @kitql/eslint-config --D
|
|
|
16
16
|
### eslint config
|
|
17
17
|
|
|
18
18
|
`.eslintrc.js`
|
|
19
|
+
|
|
19
20
|
```js
|
|
20
21
|
module.exports = {
|
|
21
|
-
|
|
22
|
-
'@kitql',
|
|
23
|
-
],
|
|
22
|
+
extends: ['@kitql']
|
|
24
23
|
}
|
|
25
24
|
```
|
|
26
25
|
|
|
27
26
|
### prettier config
|
|
28
27
|
|
|
29
28
|
`.prettierrc.cjs`
|
|
29
|
+
|
|
30
30
|
```js
|
|
31
31
|
const config = require('@kitql/eslint-config/.prettierrc.cjs')
|
|
32
32
|
|
|
33
33
|
module.exports = {
|
|
34
|
-
...config
|
|
34
|
+
...config
|
|
35
35
|
// Some custom things?
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
```
|
|
39
38
|
|
|
40
39
|
### usage
|
|
@@ -47,9 +46,9 @@ npm exec kitql-lint
|
|
|
47
46
|
npm exec kitql-lint --format
|
|
48
47
|
```
|
|
49
48
|
|
|
50
|
-
##
|
|
49
|
+
## ⭐️ Join us
|
|
51
50
|
|
|
52
51
|
[](https://github.com/jycouet/kitql)
|
|
53
52
|
|
|
54
|
-
💡 _[KitQL](https://www.kitql.dev/docs) itself is not a library, it's "nothing" but a collection of
|
|
55
|
-
|
|
53
|
+
💡 _[KitQL](https://www.kitql.dev/docs) itself is not a library, it's "nothing" but a collection of
|
|
54
|
+
standalone libraries._
|
package/cmd.js
CHANGED
|
@@ -1,50 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { Log, red } from '@kitql/helpers'
|
|
2
3
|
import { spawn, spawnSync } from 'child_process'
|
|
3
4
|
import { program, Option } from 'commander'
|
|
4
5
|
import fs from 'fs'
|
|
5
6
|
|
|
7
|
+
const log = new Log('kitql-lint')
|
|
8
|
+
|
|
6
9
|
program.addOption(new Option('-f, --format', 'format'))
|
|
7
10
|
|
|
8
11
|
program.parse(process.argv)
|
|
9
12
|
const options_cli = program.opts()
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Still nothing
|
|
14
|
+
const findFileOrUp = fileName => {
|
|
15
|
+
// Find file recursively 4 levels max up
|
|
16
|
+
for (let i = 0; i < 4; i++) {
|
|
17
|
+
try {
|
|
18
|
+
const path = '../'.repeat(i) + fileName
|
|
19
|
+
if (fs.statSync(path)) {
|
|
20
|
+
return path
|
|
21
|
+
}
|
|
22
|
+
} catch (error) {
|
|
23
|
+
// nothing to do
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
|
-
}
|
|
25
|
-
if (!pathPrettierIgnore) {
|
|
26
|
-
console.error(`.prettierignore not found`)
|
|
27
|
-
process.exit(0)
|
|
28
|
-
}
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
fs.statSync('.prettierrc.cjs')
|
|
33
|
-
pathPrettierCjs = '.prettierrc.cjs'
|
|
34
|
-
} catch (error) {
|
|
35
|
-
try {
|
|
36
|
-
fs.statSync('../../.prettierrc.cjs')
|
|
37
|
-
pathPrettierCjs = '../../.prettierrc.cjs'
|
|
38
|
-
} catch (error) {
|
|
39
|
-
// Still nothing
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (!pathPrettierCjs) {
|
|
43
|
-
console.error(`.prettierrc.cjs not found`)
|
|
44
|
-
process.exit(0)
|
|
27
|
+
log.error(red(`${fileName} not found`))
|
|
28
|
+
process.exit(1)
|
|
45
29
|
}
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
let pathPrettierIgnore = findFileOrUp('.prettierignore')
|
|
32
|
+
let pathPrettierCjs = findFileOrUp('.prettierrc.cjs')
|
|
48
33
|
|
|
49
34
|
const format = options_cli.format ?? false
|
|
50
35
|
|
|
@@ -60,26 +45,46 @@ const cmdPrettier =
|
|
|
60
45
|
`${format ? ' --write' : ''}` +
|
|
61
46
|
// exec
|
|
62
47
|
` .`
|
|
63
|
-
|
|
48
|
+
let result_prettier = spawn(cmdPrettier, {
|
|
64
49
|
shell: true,
|
|
65
|
-
|
|
66
|
-
stdio: '
|
|
50
|
+
cwd: process.cwd(),
|
|
51
|
+
stdio: 'pipe',
|
|
67
52
|
})
|
|
68
53
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
54
|
+
// let's not log anything when we are formating prettier
|
|
55
|
+
if (!format) {
|
|
56
|
+
const logPrettier = new Log('kitql-lint prettier')
|
|
57
|
+
result_prettier.stdout.on('data', data => {
|
|
58
|
+
logPrettier.error(data.toString())
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
result_prettier.on('close', code => {
|
|
63
|
+
// Then eslint
|
|
64
|
+
const cmdEsLint =
|
|
65
|
+
`eslint` +
|
|
66
|
+
// ignore?
|
|
67
|
+
` --ignore-path ${pathPrettierIgnore}` +
|
|
68
|
+
// format or not
|
|
69
|
+
`${format ? ' --fix' : ''}` +
|
|
70
|
+
// exec
|
|
71
|
+
` .`
|
|
72
|
+
|
|
73
|
+
// log.info(cmdEsLint)
|
|
74
|
+
|
|
75
|
+
let result_eslint = spawnSync(cmdEsLint, {
|
|
76
|
+
shell: true,
|
|
77
|
+
cwd: process.cwd(),
|
|
78
|
+
stdio: 'inherit',
|
|
79
|
+
})
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
if (result_eslint.status) {
|
|
82
|
+
log.error(red(`eslint failed, check logs above.`))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (code === 0 && result_eslint.status === 0) {
|
|
86
|
+
log.success(`All good, your files looks great!`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
process.exit(code || result_eslint.status)
|
|
90
|
+
})
|
package/index.cjs
CHANGED
|
@@ -2,9 +2,8 @@ module.exports = {
|
|
|
2
2
|
root: true,
|
|
3
3
|
parser: '@typescript-eslint/parser',
|
|
4
4
|
extends: [
|
|
5
|
-
'@theguild',
|
|
6
|
-
'@theguild/eslint-config/
|
|
7
|
-
'@theguild/eslint-config/mdx',
|
|
5
|
+
// '@theguild',
|
|
6
|
+
// '@theguild/eslint-config/mdx',
|
|
8
7
|
'@theguild/eslint-config/json',
|
|
9
8
|
'@theguild/eslint-config/yml',
|
|
10
9
|
'eslint:recommended',
|
|
@@ -42,6 +41,7 @@ module.exports = {
|
|
|
42
41
|
},
|
|
43
42
|
},
|
|
44
43
|
],
|
|
44
|
+
ignorePatterns: ['*.md'],
|
|
45
45
|
parserOptions: {
|
|
46
46
|
sourceType: 'module',
|
|
47
47
|
ecmaVersion: 2020,
|
package/package.json
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
"name": "@kitql/eslint-config",
|
|
3
3
|
"description": "opinionated linting and formatting for projects",
|
|
4
4
|
"keywords": [
|
|
5
|
-
"cli"
|
|
5
|
+
"cli",
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslint-config"
|
|
6
8
|
],
|
|
7
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.1.0-next.0",
|
|
8
10
|
"license": "MIT",
|
|
9
11
|
"type": "module",
|
|
10
12
|
"repository": {
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
"main": "index.cjs",
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"@graphql-eslint/eslint-plugin": "3.20.1",
|
|
24
|
+
"@kitql/helpers": "0.8.8-next.0",
|
|
22
25
|
"@theguild/eslint-config": "^0.11.1",
|
|
23
26
|
"@theguild/prettier-config": "2.0.2",
|
|
24
27
|
"@trivago/prettier-plugin-sort-imports": "4.3.0",
|
|
@@ -49,7 +52,8 @@
|
|
|
49
52
|
".prettierrc.cjs"
|
|
50
53
|
],
|
|
51
54
|
"scripts": {
|
|
52
|
-
"
|
|
55
|
+
"lint": "node ./cmd.js",
|
|
56
|
+
"format": "node ./cmd.js -f",
|
|
53
57
|
"lint:example": "kitql-lint",
|
|
54
58
|
"format:example": "kitql-lint --format"
|
|
55
59
|
}
|