standard-tsx 0.0.4 → 0.0.6
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/HISTORY.md +6 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/eslint.config.js +14 -50
- package/src/utils.js +63 -0
package/HISTORY.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 0.0.6
|
|
2
|
+
* [Disable duplicate ts rules (#14)](https://github.com/extremeheat/standard-tsx/commit/625d956de1b1f98e57af040d7284d1fec0b93274) (thanks @extremeheat)
|
|
3
|
+
|
|
4
|
+
## 0.0.5
|
|
5
|
+
* [Update .gitignore handling (#12)](https://github.com/extremeheat/standard-tsx/commit/29b2286623bf5145ec6c8b3d112136f9d0b7ccac) (thanks @extremeheat)
|
|
6
|
+
|
|
1
7
|
## 0.0.4
|
|
2
8
|
* [Fix tsconfig lookup (#9)](https://github.com/extremeheat/standard-tsx/commit/4f28fc3798d52a35d86126c29a7e5d3d341b1578) (thanks @extremeheat)
|
|
3
9
|
* [Fix .gitignore handling in eslint.config.js](https://github.com/extremeheat/standard-tsx/commit/a8d88a03742b02b7138d9b653026eb33a74ce829) (thanks @extremeheat)
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://gitpod.io/#https://github.com/extremeheat/standard-tsx)
|
|
5
5
|
|
|
6
6
|
A drop-in replacement for the `standard` JavaScript linter that supports both TypeScript and JavaScript code with and without JSX. This package does not
|
|
7
|
-
add any new rules. Instead, it applies standard's eslint config (https://github.com/standard/eslint-config-standard) to both `*.ts` and `*.js`/`.cjs`/`.mjs` files as well as `.tsx`/`.jsx` React files. This is on top of ESLint's default TypeScript reccomendations (which are mostly non-style related):
|
|
7
|
+
add any new JavaScript rules. Instead, it applies standard's eslint config (https://github.com/standard/eslint-config-standard) to both `*.ts` and `*.js`/`.cjs`/`.mjs` files as well as `.tsx`/`.jsx` React files. This is on top of ESLint's default TypeScript reccomendations (which are mostly non-style related) and add some `--fix`-able TypeScript rules to mirror standard's JavaScript behavior (semicolons, spacing):
|
|
8
8
|
|
|
9
9
|
>Recommended rules for code correctness that you can drop in without additional configuration. These rules are those whose reports are almost always for a bad practice and/or likely bug. recommended also disables core ESLint rules known to conflict with typescript-eslint rules or cause issues in TypeScript codebases.
|
|
10
10
|
|
package/package.json
CHANGED
package/src/eslint.config.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// ./eslint.config.js
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const fs = require('node:fs')
|
|
4
|
-
|
|
5
1
|
const globals = require('globals')
|
|
6
2
|
const pluginJs = require('@eslint/js').configs
|
|
7
3
|
const tseslint = require('typescript-eslint')
|
|
@@ -12,52 +8,18 @@ const promisePlugin = require('eslint-plugin-promise')
|
|
|
12
8
|
const eslintEnvRestorePlugin = require('eslint-plugin-eslint-env-restore')
|
|
13
9
|
const reactPlugin = require('eslint-plugin-react')
|
|
14
10
|
const reactHooksPlugin = require('eslint-plugin-react-hooks')
|
|
15
|
-
const glob = require('glob')
|
|
16
|
-
|
|
17
|
-
// Find all .gitignore files in the project
|
|
18
|
-
const gitignoreFiles = glob.sync('**/.gitignore', { cwd: process.cwd() })
|
|
19
|
-
|
|
20
|
-
// Sort by directory depth (root to leaves) to match Git's override behavior
|
|
21
|
-
const sortedGitignoreFiles = gitignoreFiles.sort((a, b) => {
|
|
22
|
-
const depthA = a.split(path.sep).length
|
|
23
|
-
const depthB = b.split(path.sep).length
|
|
24
|
-
return depthA - depthB
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
// Merge ignore patterns from all .gitignore files
|
|
28
|
-
const ignorePatterns = []
|
|
29
|
-
for (const file of sortedGitignoreFiles) {
|
|
30
|
-
const dir = path.dirname(file)
|
|
31
|
-
const content = fs.readFileSync(file, 'utf8')
|
|
32
|
-
const lines = content.split('\n').map(line => line.trim()).filter(line => line && !line.startsWith('#'))
|
|
33
|
-
for (const line of lines) {
|
|
34
|
-
if (line.startsWith('!')) {
|
|
35
|
-
ignorePatterns.push('!' + path.join(dir, line.slice(1)))
|
|
36
|
-
} else {
|
|
37
|
-
ignorePatterns.push(path.join(dir, line))
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
11
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
while (true) {
|
|
46
|
-
const tsconfigPath = path.join(currentDir, 'tsconfig.json')
|
|
47
|
-
if (fs.existsSync(tsconfigPath)) {
|
|
48
|
-
return currentDir
|
|
49
|
-
}
|
|
12
|
+
const { collectIgnores, findNearestTsconfigDir } = require('./utils.js')
|
|
13
|
+
const ignorePatterns = collectIgnores()
|
|
14
|
+
const tsconfigRootDir = findNearestTsconfigDir()
|
|
50
15
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
return null
|
|
16
|
+
const tsRules = {
|
|
17
|
+
// TODO: Need stylistic
|
|
18
|
+
// '@typescript-eslint/indent': ['error', 2],
|
|
19
|
+
// '@typescript-eslint/semi': ['error', 'never'],
|
|
20
|
+
// '@typescript-eslint/quotes': ['error', 'single'],
|
|
21
|
+
// '@typescript-eslint/type-annotation-spacing': ['error']
|
|
59
22
|
}
|
|
60
|
-
const tsconfigRootDir = findNearestTsconfigDir()
|
|
61
23
|
|
|
62
24
|
module.exports = [
|
|
63
25
|
{ ignores: ignorePatterns },
|
|
@@ -151,7 +113,8 @@ module.exports = [
|
|
|
151
113
|
...tseslint.configs.recommended.rules,
|
|
152
114
|
...standard.rules,
|
|
153
115
|
'no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
|
|
154
|
-
'@typescript-eslint/no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }]
|
|
116
|
+
// '@typescript-eslint/no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
|
|
117
|
+
...tsRules
|
|
155
118
|
}
|
|
156
119
|
},
|
|
157
120
|
// TSX (Browser environment)
|
|
@@ -186,10 +149,11 @@ module.exports = [
|
|
|
186
149
|
...reactPlugin.configs.recommended.rules,
|
|
187
150
|
...reactHooksPlugin.configs.recommended.rules,
|
|
188
151
|
'no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
|
|
189
|
-
'@typescript-eslint/no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
|
|
152
|
+
// '@typescript-eslint/no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
|
|
190
153
|
'react/jsx-uses-react': 'off',
|
|
191
154
|
'react/jsx-uses-vars': 'error',
|
|
192
|
-
'react/react-in-jsx-scope': 'off'
|
|
155
|
+
'react/react-in-jsx-scope': 'off',
|
|
156
|
+
...tsRules
|
|
193
157
|
}
|
|
194
158
|
}
|
|
195
159
|
]
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const path = require('node:path')
|
|
2
|
+
const fs = require('node:fs')
|
|
3
|
+
const glob = require('glob')
|
|
4
|
+
|
|
5
|
+
function collectIgnores () {
|
|
6
|
+
// Find all .gitignore files in the project (upto 2 levels up for monorepo support)
|
|
7
|
+
const gitignoreFiles = glob.sync('**/.gitignore', { cwd: process.cwd() })
|
|
8
|
+
if (gitignoreFiles.length === 0) {
|
|
9
|
+
gitignoreFiles.push(...glob.sync('**/.gitignore', { cwd: path.join(process.cwd(), '..') }).map(file => path.join('..', file)))
|
|
10
|
+
if (gitignoreFiles.length === 0) {
|
|
11
|
+
gitignoreFiles.push(...glob.sync('**/.gitignore', { cwd: path.join(process.cwd(), '../..') }).map(file => path.join('..', '..', file)))
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Sort by directory depth (root to leaves) to match Git's override behavior
|
|
16
|
+
const sortedGitignoreFiles = gitignoreFiles.sort((a, b) => {
|
|
17
|
+
const depthA = a.split(path.sep).length
|
|
18
|
+
const depthB = b.split(path.sep).length
|
|
19
|
+
return depthA - depthB
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// Merge ignore patterns from all .gitignore files
|
|
23
|
+
const ignorePatterns = []
|
|
24
|
+
for (const file of sortedGitignoreFiles) {
|
|
25
|
+
const dir = path.dirname(file)
|
|
26
|
+
const content = fs.readFileSync(file, 'utf8')
|
|
27
|
+
const lines = content.split('\n').map(line => line.trim()).filter(line => line && !line.startsWith('#'))
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
let rule = path.join(dir, line).replaceAll('\\', '/')
|
|
30
|
+
if (rule.startsWith('..//')) continue // a rule intended for a parent directory
|
|
31
|
+
// rules that don't start with slash apply to all directories
|
|
32
|
+
rule = rule.replaceAll('../', '')
|
|
33
|
+
// mimic .gitignore behavior as ESlint is a bit different and doesn't recursively apply rules
|
|
34
|
+
if (!rule.startsWith('/') || !rule.startsWith('./') || !rule.startsWith('*')) rule = '**/' + rule
|
|
35
|
+
// Restore ordering of ! to front after above transformation
|
|
36
|
+
if (line.startsWith('!')) rule = '!' + rule.replaceAll('!', '')
|
|
37
|
+
ignorePatterns.push(rule)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return ignorePatterns
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function findNearestTsconfigDir (startDir = process.cwd()) {
|
|
45
|
+
let currentDir = path.resolve(startDir)
|
|
46
|
+
|
|
47
|
+
while (true) {
|
|
48
|
+
const tsconfigPath = path.join(currentDir, 'tsconfig.json')
|
|
49
|
+
if (fs.existsSync(tsconfigPath)) {
|
|
50
|
+
return currentDir
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const parentDir = path.dirname(currentDir)
|
|
54
|
+
if (parentDir === currentDir) {
|
|
55
|
+
// Reached filesystem root
|
|
56
|
+
break
|
|
57
|
+
}
|
|
58
|
+
currentDir = parentDir
|
|
59
|
+
}
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { collectIgnores, findNearestTsconfigDir }
|