@kitql/eslint-config 0.0.3 → 0.1.0-next.1

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.
Files changed (4) hide show
  1. package/README.md +8 -9
  2. package/cmd.js +57 -52
  3. package/index.cjs +14 -4
  4. package/package.json +10 -6
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![](https://img.shields.io/npm/v/@kitql/eslint-config?color=&logo=npm)](https://www.npmjs.com/package/@kitql/eslint-config)
4
4
  [![](https://img.shields.io/npm/dm/@kitql/eslint-config?&logo=npm)](https://www.npmjs.com/package/@kitql/eslint-config)
5
5
 
6
- ## 📖 Read the doc
6
+ ## 📖 Read the doc
7
7
 
8
8
  [![](https://img.shields.io/badge/Documentation%20of-kitql%20lint%20format-FF3E00.svg?style=flat&logo=stackblitz&logoColor=FF3E00)](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
- extends: [
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
- ## ⭐️ Join us
49
+ ## ⭐️ Join us
51
50
 
52
51
  [![GitHub Repo stars](https://img.shields.io/github/stars/jycouet/kitql?logo=github&label=KitQL&color=#4ACC31)](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 standalone libraries._
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
- // console.info(`options_cli`, options_cli)
12
-
13
- let pathPrettierIgnore = ''
14
- try {
15
- fs.statSync('.prettierignore')
16
- pathPrettierIgnore = '.prettierignore'
17
- } catch (error) {
18
- try {
19
- fs.statSync('../../.prettierignore')
20
- pathPrettierIgnore = '../../.prettierignore'
21
- } catch (error) {
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
- let pathPrettierCjs = ''
31
- try {
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
- // --config <path>
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
- spawnSync(cmdPrettier, {
48
+ let result_prettier = spawn(cmdPrettier, {
64
49
  shell: true,
65
- // cwd: process.cwd(),
66
- stdio: 'inherit',
50
+ cwd: process.cwd(),
51
+ stdio: 'pipe',
67
52
  })
68
53
 
69
- // Then eslint
70
- const cmdEsLint =
71
- `eslint` +
72
- // ignore?
73
- ` --ignore-path ${pathPrettierIgnore}` +
74
- // format or not
75
- `${format ? ' --fix' : ''} ` +
76
- // exec
77
- ` "*"`
78
- spawnSync(cmdEsLint, {
79
- shell: true,
80
- // cwd: process.cwd(),
81
- stdio: 'inherit',
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
- // console.log(`cmdPrettier`, cmdPrettier)
85
- // console.log(`cmdEsLint`, cmdEsLint)
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/react',
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',
@@ -14,8 +13,17 @@ module.exports = {
14
13
  ],
15
14
  plugins: ['unused-imports', 'svelte', '@typescript-eslint'],
16
15
  rules: {
17
- 'no-console': ['error', { allow: ['info', 'warn', 'error', 'time', 'timeEnd'] }],
16
+ 'no-console': ['error', { allow: ['info', 'warn', 'error', 'time', 'timeEnd', 'dir'] }],
18
17
  'unused-imports/no-unused-imports': 'error',
18
+ '@typescript-eslint/no-unused-vars': [
19
+ 'warn',
20
+ {
21
+ argsIgnorePattern: '^_',
22
+ varsIgnorePattern: '^_',
23
+ caughtErrorsIgnorePattern: '^_',
24
+ },
25
+ ],
26
+ 'no-empty': ['error', { allowEmptyCatch: true }],
19
27
  '@typescript-eslint/ban-ts-ignore': 'off',
20
28
  '@typescript-eslint/ban-ts-comment': 'off',
21
29
  '@typescript-eslint/no-explicit-any': 'off',
@@ -39,9 +47,11 @@ module.exports = {
39
47
  extends: ['plugin:@graphql-eslint/schema-all', 'plugin:@graphql-eslint/operations-all'],
40
48
  rules: {
41
49
  '@graphql-eslint/alphabetize': 'off',
50
+ '@graphql-eslint/no-one-place-fragments': 'off',
42
51
  },
43
52
  },
44
53
  ],
54
+ ignorePatterns: ['*.md'],
45
55
  parserOptions: {
46
56
  sourceType: 'module',
47
57
  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.3",
9
+ "version": "0.1.0-next.1",
8
10
  "license": "MIT",
9
11
  "type": "module",
10
12
  "repository": {
@@ -19,14 +21,15 @@
19
21
  "main": "index.cjs",
20
22
  "dependencies": {
21
23
  "@graphql-eslint/eslint-plugin": "3.20.1",
24
+ "@kitql/helpers": "0.8.8-next.1",
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",
25
- "@typescript-eslint/eslint-plugin": "6.14.0",
26
- "@typescript-eslint/parser": "6.14.0",
28
+ "@typescript-eslint/eslint-plugin": "6.15.0",
29
+ "@typescript-eslint/parser": "6.15.0",
27
30
  "@vue/compiler-sfc": "3.3.4",
28
31
  "commander": "^11.1.0",
29
- "eslint": "8.55.0",
32
+ "eslint": "8.56.0",
30
33
  "eslint-config-prettier": "9.1.0",
31
34
  "eslint-plugin-svelte": "2.35.0",
32
35
  "eslint-plugin-unused-imports": "3.0.0",
@@ -49,7 +52,8 @@
49
52
  ".prettierrc.cjs"
50
53
  ],
51
54
  "scripts": {
52
- "dev": "node ./cmd.js",
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
  }