Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip parseESlint if eslint filepath is a js file #510

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@
? resolve(root, 'auto-imports.d.ts')
: resolve(root, preferDTS)

const multilineCommentsRE = /\/\*.*?\*\//gms

Check warning on line 114 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

The 'm' flag is unnecessary because the pattern does not contain start (^) or end ($) assertions
const singlelineCommentsRE = /\/\/.*$/gm
const dtsReg = /declare\s+global\s*{(.*?)[\n\r]}/s

Check failure on line 116 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

Unescaped source character '{'

Check failure on line 116 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

Unescaped source character '}'
const componentCustomPropertiesReg = /interface\s+ComponentCustomProperties\s*{(.*?)[\n\r]}/gs

Check failure on line 117 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

Unescaped source character '{'

Check failure on line 117 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

Unescaped source character '}'
function parseDTS(dts: string) {
dts = dts
.replace(multilineCommentsRE, '')
Expand All @@ -124,7 +124,7 @@
if (!code)
return

return Object.fromEntries(Array.from(code.matchAll(/['"]?(const\s*[^\s'"]+)['"]?\s*:\s*(.+?)[,;\r\n]/g)).map(i => [i[1], i[2]]))

Check failure on line 127 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

The quantifier '[^\s'"]+' can exchange characters with '.+?'. Using any string accepted by /:+/, this can be exploited to cause at least polynomial backtracking

Check failure on line 127 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

The quantifier '[^\s'"]+' can exchange characters (:) with '.+?'. This makes the capturing group misleading, because the quantifier will capture fewer characters than its pattern suggests

Check failure on line 127 in src/core/ctx.ts

View workflow job for this annotation

GitHub Actions / lint

The quantifier '\s*' can exchange characters with '.+?'. Using any string accepted by /[\t\x0b\f \xa0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+/, this can be exploited to cause at least polynomial backtracking
}

async function generateDTS(file: string) {
Expand Down Expand Up @@ -161,10 +161,16 @@
return currentContent
}

async function parseESLint() {
const configStr = existsSync(eslintrc.filepath!) ? await fs.readFile(eslintrc.filepath!, 'utf-8') : ''
async function parseESLint(): Promise<Record<string, ESLintGlobalsPropValue>> {
if (!eslintrc.filepath)
return {}
if (eslintrc.filepath.match(/\.[cm]?[jt]sx?$/)) // Skip JavaScript-like files
return {}
const configStr = existsSync(eslintrc.filepath!)
? await fs.readFile(eslintrc.filepath!, 'utf-8')
: ''
const config = JSON.parse(configStr || '{ "globals": {} }')
return config.globals as Record<string, ESLintGlobalsPropValue>
return config.globals
}

async function generateESLint() {
Expand Down
Loading