Skip to content

Commit

Permalink
feat: fork so1ve/eslint-parser-plain (#7)
Browse files Browse the repository at this point in the history
* feat: fork so1ve/eslint-parser-plain

Co-authored-by: auvred <[email protected]>

* feat: use local eslint-parser-plain package

---------

Co-authored-by: auvred <[email protected]>
  • Loading branch information
Garfield550 and auvred authored Jan 1, 2025
1 parent 54224df commit a8ebeb1
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 21 deletions.
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dictionaryDefinitions: []
dictionaries: []
words:
- arthurgeron
- auvred
- bttin
- callees
- cjsx
Expand Down
1 change: 1 addition & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default config(
files: [
'packages/eslint-config/src/utils/get-package-json.ts',
'packages/eslint-config/src/utils/load-local-file.ts',
'packages/eslint-parser-plain/src/index.ts',
],
rules: {
'unicorn/no-null': 'off',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"yarn": ">=999.0.0"
},
"scripts": {
"build": "jiek build --filter @bttin/*",
"build": "jiek build --noMin --filter @bttin/*",
"test": "vitest --run --logHeapUsage",
"coverage": "vitest run --coverage",
"typegen": "tsx scripts/typegen.ts",
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-parser-plain/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022 Ray <https://github.com/so1ve>
Copyright (c) 2024-present Biscuit Tin <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions packages/eslint-parser-plain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# @bttin/eslint-parser-plain

Allow you to parse various types of files with ESLint, a fork of [Ray's](https://github.com/so1ve/eslint-parser-plain) ([@so1ve](https://github.com/so1ve)).

## Usages

### Install

```bash
npm install -D @bttin/eslint-parser-plain
```

```bash
yarn add -D @bttin/eslint-parser-plain
```

```bash
pnpm add -D @bttin/eslint-parser-plain
```

### Configure

We recommend using [ESLint's Flat Config format](https://eslint.org/docs/latest/use/configure/configuration-files-new).

```typescript
import parserPlain from "@bttin/eslint-parser-plain"

export default [
{
files: ["*.md"],
parser: parserPlain,
rules: {
"prettier/prettier": ["error", { parser: "markdown" }],
},
},
];
```

Or legacy config format:

```typescript
module.exports = {
overrides: [
{
files: ["*.md"],
parser: "eslint-parser-plain",
rules: {
"prettier/prettier": ["error", { parser: "markdown" }],
},
},
],
};
```

## Credits

- Ray ([@so1ve](https://github.com/so1ve))
- auvred ([@auvred](https://github.com/auvred))

## License

[MIT](./LICENSE) License

Copyright (c) 2022 Ray <https://github.com/so1ve>
<br />
Copyright (c) 2024-present Biscuit Tin <[email protected]>
41 changes: 41 additions & 0 deletions packages/eslint-parser-plain/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@bttin/eslint-parser-plain",
"type": "module",
"version": "0.0.1",
"description": "Parse various types of files with ESLint, a fork of Ray's (@so1ve).",
"author": "Biscuit Tin <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/BiscuitTin/eslint-config/tree/main/packages/eslint-parser-plain#readme",
"repository": {
"type": "git",
"url": "https://github.com/BiscuitTin/eslint-config.git",
"directory": "packages/eslint-parser-plain"
},
"bugs": "https://github.com/BiscuitTin/eslint-config/issues",
"keywords": [
"eslint",
"eslint-parser"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"files": [
"dist"
],
"scripts": {
"prepublish": "jiek build && jiek",
"postpublish": "jiek"
},
"peerDependencies": {
"eslint": "^9.0.0"
},
"peerDependenciesMeta": {
"eslint": {
"optional": false
}
},
"devDependencies": {
"eslint": "^9.17.0"
}
}
23 changes: 23 additions & 0 deletions packages/eslint-parser-plain/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { name, version } from '../package.json'

export const meta = { name, version }

export function parseForESLint(code: string) {
return {
ast: {
type: 'Program',
loc: { start: 0, end: code.length },
range: [0, code.length],
body: [],
comments: [],
tokens: [],
},
services: { isPlain: true },
scopeManager: null,
visitorKeys: {
Program: [],
},
}
}

export default { meta, parseForESLint }
32 changes: 32 additions & 0 deletions packages/eslint-parser-plain/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { parseForESLint } from '@bttin/eslint-parser-plain'
import { describe, expect, it } from 'vitest'

describe('should', () => {
it('work', () => {
expect(parseForESLint('{ "a": 1 }')).toMatchInlineSnapshot(`
{
"ast": {
"body": [],
"comments": [],
"loc": {
"end": 10,
"start": 0,
},
"range": [
0,
10,
],
"tokens": [],
"type": "Program",
},
"scopeManager": null,
"services": {
"isPlain": true,
},
"visitorKeys": {
"Program": [],
},
}
`)
})
})
1 change: 1 addition & 0 deletions packages/eslint-plugin-format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ Thanks to the existing works for references and inspiration.
[MIT](./LICENSE) License

Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
<br />
Copyright (c) 2024-present Biscuit Tin <[email protected]>
3 changes: 1 addition & 2 deletions packages/eslint-plugin-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@
}
},
"dependencies": {
"@bttin/eslint-parser-plain": "workspace:^",
"eslint-formatting-reporter": "^0.0.0",
"eslint-parser-plain": "^0.1.0",
"find-up-simple": "^1.0.0",
"local-pkg": "^0.5.1",
"micro-memoize": "^4.1.2",
"synckit": "^0.9.2",
"valibot": "1.0.0-beta.9"
Expand Down
13 changes: 1 addition & 12 deletions packages/eslint-plugin-format/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ESLint, Linter } from 'eslint'

import { parseForESLint } from 'eslint-parser-plain'
import { getPackageInfoSync } from 'local-pkg'
import parserPlain from '@bttin/eslint-parser-plain'

import packagePlugin from '../package.json'
import dprint from './rules/dprint.js'
Expand All @@ -11,16 +10,6 @@ interface PluginWithParser extends ESLint.Plugin {
parserPlain: Linter.Parser
}

const packageParserPlain = getPackageInfoSync('eslint-parser-plain')

const parserPlain: Linter.Parser = {
meta: {
name: packageParserPlain?.name,
version: packageParserPlain?.version,
},
parseForESLint,
}

export default {
parserPlain,
meta: {
Expand Down
15 changes: 9 additions & 6 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions tsconfigs/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"../packages/*/src/**/*.node.ts",
"../packages/eslint-config/src",
"../packages/eslint-config/eslint-inspector.config.ts",
"../packages/eslint-parser-plain/src",
"../packages/eslint-plugin-format/src"
]
}

0 comments on commit a8ebeb1

Please sign in to comment.