standard-tsx 0.0.3 → 0.0.4
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 +4 -0
- package/package.json +1 -1
- package/src/eslint.config.js +43 -11
- package/src/env-restore.js +0 -41
package/HISTORY.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## 0.0.4
|
|
2
|
+
* [Fix tsconfig lookup (#9)](https://github.com/extremeheat/standard-tsx/commit/4f28fc3798d52a35d86126c29a7e5d3d341b1578) (thanks @extremeheat)
|
|
3
|
+
* [Fix .gitignore handling in eslint.config.js](https://github.com/extremeheat/standard-tsx/commit/a8d88a03742b02b7138d9b653026eb33a74ce829) (thanks @extremeheat)
|
|
4
|
+
|
|
1
5
|
## 0.0.3
|
|
2
6
|
* [Update README.md](https://github.com/extremeheat/standard-tsx/commit/0f6de2eac2d90cec95ad49ef887cfca79e6e35d1) (thanks @extremeheat)
|
|
3
7
|
* [Update eslint.config.js - glob: ignore node_modules](https://github.com/extremeheat/standard-tsx/commit/7f5f6735c0baebc1923ef86d12cbd00a1db22032) (thanks @extremeheat)
|
package/package.json
CHANGED
package/src/eslint.config.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// ./eslint.config.js
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
const fs = require('node:fs')
|
|
4
|
+
|
|
2
5
|
const globals = require('globals')
|
|
3
6
|
const pluginJs = require('@eslint/js').configs
|
|
4
7
|
const tseslint = require('typescript-eslint')
|
|
@@ -9,12 +12,10 @@ const promisePlugin = require('eslint-plugin-promise')
|
|
|
9
12
|
const eslintEnvRestorePlugin = require('eslint-plugin-eslint-env-restore')
|
|
10
13
|
const reactPlugin = require('eslint-plugin-react')
|
|
11
14
|
const reactHooksPlugin = require('eslint-plugin-react-hooks')
|
|
12
|
-
|
|
13
|
-
const { includeIgnoreFile } = require('@eslint/compat')
|
|
14
|
-
const path = require('node:path')
|
|
15
15
|
const glob = require('glob')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Find all .gitignore files in the project
|
|
18
|
+
const gitignoreFiles = glob.sync('**/.gitignore', { cwd: process.cwd() })
|
|
18
19
|
|
|
19
20
|
// Sort by directory depth (root to leaves) to match Git's override behavior
|
|
20
21
|
const sortedGitignoreFiles = gitignoreFiles.sort((a, b) => {
|
|
@@ -23,14 +24,43 @@ const sortedGitignoreFiles = gitignoreFiles.sort((a, b) => {
|
|
|
23
24
|
return depthA - depthB
|
|
24
25
|
})
|
|
25
26
|
|
|
26
|
-
//
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
|
|
42
|
+
function findNearestTsconfigDir (startDir = process.cwd()) {
|
|
43
|
+
let currentDir = path.resolve(startDir)
|
|
44
|
+
|
|
45
|
+
while (true) {
|
|
46
|
+
const tsconfigPath = path.join(currentDir, 'tsconfig.json')
|
|
47
|
+
if (fs.existsSync(tsconfigPath)) {
|
|
48
|
+
return currentDir
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const parentDir = path.dirname(currentDir)
|
|
52
|
+
if (parentDir === currentDir) {
|
|
53
|
+
// Reached filesystem root
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
currentDir = parentDir
|
|
57
|
+
}
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
const tsconfigRootDir = findNearestTsconfigDir()
|
|
31
61
|
|
|
32
62
|
module.exports = [
|
|
33
|
-
|
|
63
|
+
{ ignores: ignorePatterns },
|
|
34
64
|
{
|
|
35
65
|
languageOptions: {
|
|
36
66
|
globals: {
|
|
@@ -102,7 +132,8 @@ module.exports = [
|
|
|
102
132
|
languageOptions: {
|
|
103
133
|
parser: tseslint.parser,
|
|
104
134
|
parserOptions: {
|
|
105
|
-
project: './tsconfig.json'
|
|
135
|
+
project: './tsconfig.json',
|
|
136
|
+
tsconfigRootDir
|
|
106
137
|
},
|
|
107
138
|
globals: {
|
|
108
139
|
...globals.node
|
|
@@ -130,6 +161,7 @@ module.exports = [
|
|
|
130
161
|
parser: tseslint.parser,
|
|
131
162
|
parserOptions: {
|
|
132
163
|
project: './tsconfig.json',
|
|
164
|
+
tsconfigRootDir,
|
|
133
165
|
ecmaFeatures: {
|
|
134
166
|
jsx: true
|
|
135
167
|
}
|
package/src/env-restore.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// ./env-restore.js
|
|
2
|
-
const envGlobals = require('globals')
|
|
3
|
-
|
|
4
|
-
function extractEslintEnv (text) {
|
|
5
|
-
const firstLine = text.split('\n')[0].trim()
|
|
6
|
-
if (firstLine.startsWith('/* eslint-env ') && firstLine.endsWith('*/')) {
|
|
7
|
-
const envPart = firstLine.slice(14, -2).trim()
|
|
8
|
-
return envPart.split(',').map(env => env.trim())
|
|
9
|
-
}
|
|
10
|
-
return []
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function mapEnvsToGlobals (envs) {
|
|
14
|
-
const globals = {}
|
|
15
|
-
envs.forEach(env => {
|
|
16
|
-
if (envGlobals[env]) {
|
|
17
|
-
Object.assign(globals, envGlobals[env])
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
return globals
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
processors: {
|
|
25
|
-
js: {
|
|
26
|
-
preprocess (text, filename) {
|
|
27
|
-
const envs = extractEslintEnv(text)
|
|
28
|
-
if (envs.length === 0) return [text]
|
|
29
|
-
|
|
30
|
-
const globals = mapEnvsToGlobals(envs)
|
|
31
|
-
const globalNames = Object.keys(globals).join(', ')
|
|
32
|
-
const injectedComment = `/* global ${globalNames} */ ${text}`
|
|
33
|
-
return [injectedComment]
|
|
34
|
-
},
|
|
35
|
-
postprocess (messages) {
|
|
36
|
-
return messages[0]
|
|
37
|
-
},
|
|
38
|
-
supportsAutofix: true
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|