Skip to content

Commit

Permalink
Merge pull request #135 from zhlint-project/jinjiang/new-ignore-rc
Browse files Browse the repository at this point in the history
feat: new ignore arguments
  • Loading branch information
Jinjiang authored Jan 20, 2024
2 parents 21e6c36 + 157ba5e commit 7e2e6c9
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 45 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ zhlint --config <filepath>

# .zhlintignore by default
zhlint --ignore <filepath>
zhlint --file-ignore <filepath>

# .zhlintcaseignore by default
zhlint --case-ignore <filepath>

# current directory by default
zhlint --dir <path>
Expand All @@ -68,7 +72,9 @@ In the config file, you can write a JSON like:

For more details, see [supported rules](#supported-rules).

In the ignore file, you can write some lines of ignored cases like:
In the file-ignore file, you can write some lines to ignore files in [.gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format):

In the case-ignore file, you can write some lines of ignored cases like:

```txt
( , )
Expand Down Expand Up @@ -121,9 +127,10 @@ const value = '自动在中文和English之间加入空格'

const dir = '...' // the target directory path
const configPath = '...' // the config file path
const ignorePath = '...' // the ignore file path
const fileIgnorePath = '...' // the file-ignore file path
const caseIgnorePath = '...' // the case-ignore file path

const config = readRc(dir, configPath, ignorePath)
const config = readRc(dir, configPath, fileIgnorePath, caseIgnorePath)
const output = runWithConfig(value, config)

// ... further actions
Expand Down Expand Up @@ -167,15 +174,15 @@ type Options = {
- `hyperParse`: customize the hyper parser by their names. It could be `undefined` which means just use default [ignored cases parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/ignore.js), [Markdown parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/md.js) and the [Hexo tags parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/hexo.js).
- `ignoredCases`: provide exception cases which you would like to skip.
- `IgnoredCase`: `{ prefix?, textStart, textEnd?, suffix? }`
- Just follows a certain format inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment).
- Just follows a certain format `[prefix-,]textStart[,textEnd][,-suffix]` inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment).
- `logger`: same to the parameter in `report(...)`.
### RC Config
- `preset`: `string` (optional)
- `rules`: `RuleOptions` without the `preset` field. (optional)
- `hyperParsers`: `string[]` (optional)
- `ignores`: `string[]` and the priority is lower than `.zhlintignore`. (optional)
- `caseIgnores`: `string[]` and the priority is lower than `.zhlintcaseignore`. (optional)
### Output
Expand Down
14 changes: 11 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('fs')
const minimist = require('minimist')
const glob = require('glob')
const gitignore = require('ignore')
const { readRc, runWithConfig, report } = require('../')

const helpMessage = `
Expand All @@ -24,7 +25,11 @@ Config arguments:
.zhlintrc by default
--ignore <filepath>
--file-ignore <filepath>
.zhlintignore by default
--case-ignore <filepath>
.zhlintcaseignore by default
--dir <path>
current directory by default
Expand Down Expand Up @@ -69,11 +74,14 @@ const main = () => {
const [filePattern] = [...argv._]
const configDir = argv.dir
const configPath = argv.config
const ignorePath = argv.ignore
const config = readRc(configDir, configPath, ignorePath)
const fileIgnorePath = argv.ignore || argv['file-ignore']
const caseIgnorePath = argv['case-ignore']
const config = readRc(configDir, configPath, fileIgnorePath, caseIgnorePath)
const fileIgnore = gitignore().add(config.fileIgnores)
const fileIgnoreFilter = fileIgnore.createFilter()
try {
const files = glob.sync(filePattern)
const resultList = files.map((file) => {
const resultList = files.filter(fileIgnoreFilter).map((file) => {
console.log(`[start] ${file}`)
const origin = fs.readFileSync(file, { encoding: 'utf8' })
const { result, validations } = runWithConfig(origin, config)
Expand Down
17 changes: 12 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ zhlint --config <filepath>

# .zhlintignore by default
zhlint --ignore <filepath>
zhlint --file-ignore <filepath>

# .zhlintcaseignore by default
zhlint --case-ignore <filepath>

# current directory by default
zhlint --dir <path>
Expand All @@ -74,7 +78,9 @@ In the config file, you can write a JSON like:

For more details, see [supported rules](#supported-rules).

In the ignore file, you can write some lines of ignored cases like:
In the file-ignore file, you can write some lines to ignore files in [.gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format):

In the case-ignore file, you can write some lines of ignored cases like:

```txt
( , )
Expand Down Expand Up @@ -131,9 +137,10 @@ const value = '自动在中文和English之间加入空格'

const dir = '...' // the target directory path
const configPath = '...' // the config file path
const ignorePath = '...' // the ignore file path
const fileIgnorePath = '...' // the file-ignore file path
const caseIgnorePath = '...' // the case-ignore file path

const config = readRc(dir, configPath, ignorePath)
const config = readRc(dir, configPath, fileIgnorePath, caseIgnorePath)
const output = runWithConfig(value, config)

// ... further actions
Expand Down Expand Up @@ -179,15 +186,15 @@ type Options = {
- `hyperParse`: customize the hyper parser by their names. It could be `undefined` which means just use default [ignored cases parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/ignore.js), [Markdown parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/md.js) and the [Hexo tags parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/hexo.js).
- `ignoredCases`: provide exception cases which you would like to skip.
- `IgnoredCase`: `{ prefix?, textStart, textEnd?, suffix? }`
- Just follows a certain format inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment).
- Just follows a certain format `[prefix-,]textStart[,textEnd][,-suffix]` inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment).
- `logger`: same to the parameter in `report(...)`.
### RC Config
- `preset`: `string` (optional)
- `rules`: `RuleOptions` without the `preset` field. (optional)
- `hyperParsers`: `string[]` (optional)
- `ignores`: `string[]` and the priority is lower than `.zhlintignore`. (optional)
- `caseIgnores`: `string[]` and the priority is lower than `.zhlintcaseignore`. (optional)
### Output
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"dependencies": {
"chalk": "^4.0.0",
"glob": "^7.1.6",
"ignore": "^5.3.0",
"minimist": "^1.2.0",
"node-stdlib-browser": "^1.2.0",
"remark-frontmatter": "^1.3.2",
Expand Down
12 changes: 7 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ export const normalizeConfig = (
})

// ignored cases
if (config.ignores) {
config.ignores.forEach((x) => {
if (config.caseIgnores) {
config.caseIgnores.forEach((x) => {
const ignoredCase = parseIngoredCase(x)
if (ignoredCase) {
options.ignoredCases.push(ignoredCase)
Expand Down
Loading

0 comments on commit 7e2e6c9

Please sign in to comment.