Skip to content

Commit 6b2f35a

Browse files
authored
Update and refactor glob (#1730)
* Refactor glob usage in CLI for improved API and options Replaces deprecated or less preferred glob API usages with updated methods (globSync, globStream) in formatter and htmlhint CLI modules. Removes unused or deprecated options and updates event handling for file matching, improving maintainability and compatibility. * Update sourceMappingURL in htmlhint.js The sourceMappingURL comment at the end of dist/cli/htmlhint.js was updated, likely reflecting a new or rebuilt source map. No other code changes were made. * Update sarif.sarif
1 parent 6181096 commit 6b2f35a

File tree

8 files changed

+85
-83
lines changed

8 files changed

+85
-83
lines changed

dist/cli/formatter.js

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cli/htmlhint.js

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 57 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"async": "3.2.6",
5252
"chalk": "4.1.2",
5353
"commander": "11.1.0",
54-
"glob": "^8.1.0",
54+
"glob": "^9.0.0",
5555
"is-glob": "^4.0.3",
5656
"node-sarif-builder": "^3.2.0",
5757
"strip-json-comments": "3.1.1",
@@ -62,7 +62,6 @@
6262
"@rollup/plugin-node-resolve": "16.0.1",
6363
"@rollup/plugin-terser": "^0.4.4",
6464
"@types/async": "^3.2.25",
65-
"@types/glob": "^8.1.0",
6665
"@types/is-glob": "4.0.4",
6766
"@types/xml": "^1.0.11",
6867
"@typescript-eslint/eslint-plugin": "8.43.0",

src/cli/formatter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as chalk from 'chalk'
22
import { EventEmitter } from 'events'
3-
import { sync as globSync } from 'glob'
3+
import { globSync } from 'glob'
44
import { parse, resolve } from 'path'
55
import type { HTMLHint as IHTMLHint } from '../core/core'
66
import type { Hint, Ruleset } from '../core/types'
@@ -24,8 +24,6 @@ function loadFormatters() {
2424
cwd: __dirname,
2525
dot: false,
2626
nodir: true,
27-
strict: false,
28-
silent: true,
2927
})
3028

3129
const mapFormatters: { [name: string]: FormatterCallback } = {}

src/cli/htmlhint.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { queue as asyncQueue, series as asyncSeries } from 'async'
44
import * as chalk from 'chalk'
55
import { Command } from 'commander'
66
import { existsSync, readFileSync, statSync, writeFileSync } from 'fs'
7-
import * as glob from 'glob'
8-
import { IGlob } from 'glob'
7+
import { globStream, globSync } from 'glob'
98
import { parseGlob } from './parse-glob'
109
import { dirname, resolve, sep } from 'path'
1110
// Native fetch is available in Node.js 18+
@@ -223,13 +222,11 @@ function loadCustomRules(rulesdir: string) {
223222
if (statSync(rulesdir).isDirectory()) {
224223
rulesdir += /\/$/.test(rulesdir) ? '' : '/'
225224
rulesdir += '**/*.js'
226-
const arrFiles = glob.sync(rulesdir, {
225+
const arrFiles = globSync(rulesdir, {
227226
dot: false,
228227
nodir: true,
229-
strict: false,
230-
silent: true,
231228
})
232-
arrFiles.forEach((file) => {
229+
arrFiles.forEach((file: string) => {
233230
loadRule(file)
234231
})
235232
} else {
@@ -467,22 +464,14 @@ function walkPath(
467464
})
468465
}
469466

470-
const walk: IGlob = glob(
471-
pattern,
472-
{
473-
cwd: base,
474-
dot: false,
475-
ignore: arrIgnores,
476-
nodir: true,
477-
strict: false,
478-
silent: true,
479-
},
480-
() => {
481-
onFinish()
482-
}
483-
)
467+
const walk = globStream(pattern, {
468+
cwd: base,
469+
dot: false,
470+
ignore: arrIgnores,
471+
nodir: true,
472+
})
484473

485-
walk.on('match', (file: string) => {
474+
walk.on('data', (file: string) => {
486475
base = base.replace(/^.\//, '')
487476

488477
if (sep !== '/') {
@@ -491,6 +480,10 @@ function walkPath(
491480

492481
callback(base + file)
493482
})
483+
484+
walk.on('end', () => {
485+
onFinish()
486+
})
494487
}
495488

496489
// hint file

test/cli/formatters/sarif.sarif

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"helpUri": "https://htmlhint.com/rules/attr-no-duplication",
2727
"help": {
2828
"text": "Elements cannot have duplicate attributes.",
29-
"markdown": "\nThe same attribute can't be specified twice.\n\nLevel: Error\n\n## Config value\n\n- `true`: enable rule\n- `false`: disable rule\n\n### The following patterns are **not** considered rule violations\n\n```html\n`<img src=\"a.png\" />`\n```\n\n### The following pattern is considered a rule violation:\n\n```html\n`<img src=\"a.png\" src=\"b.png\" />`\n```"
29+
"markdown": "\nThe same attribute can't be specified twice.\n\nLevel: Error\n\n## Config value\n\n- `true`: enable rule\n- `false`: disable rule\n\n### The following patterns are **not** considered rule violations\n\n```html\n`<img src=\"a.png\" />`\n```\n\n### The following pattern is considered a rule violation:\n\n```html\n`<img src=\"a.png\" src=\"b.png\" />`\n```\n\n### Why this rule is important\n\nDuplicate attributes can cause unexpected behavior and make the code harder to read and maintain."
3030
}
3131
},
3232
{
@@ -52,7 +52,7 @@
5252
}
5353
}
5454
],
55-
"version": "1.5.1",
55+
"version": "1.7.0",
5656
"informationUri": "https://htmlhint.com/"
5757
}
5858
},

website/.htmlhintrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
"frame-title-require": true,
1717
"h1-require": true,
1818
"head-script-disabled": false,
19-
"href-abs-or-rel": false,
2019
"html-lang-require": true,
2120
"id-class-ad-disabled": true,
22-
"id-class-value": false,
2321
"id-unique": true,
2422
"inline-script-disabled": false,
2523
"inline-style-disabled": false,
@@ -29,7 +27,6 @@
2927
"meta-description-require": true,
3028
"meta-viewport-require": true,
3129
"script-disabled": false,
32-
"space-tab-mixed-disabled": false,
3330
"spec-char-escape": false,
3431
"src-not-empty": true,
3532
"style-disabled": false,

0 commit comments

Comments
 (0)