Skip to content

Commit

Permalink
chore: add eslint usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Aug 18, 2024
1 parent 80c9937 commit c4dcd85
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 16 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {

```js
// main.js
import { getRandom, buildTime } from './macros' with { type: 'macro' }
import { buildTime, getRandom } from './macros' with { type: 'macro' }

getRandom() // Will be replaced with a random number at build time
buildTime // Will be replaced with the timestamp at the build time
Expand All @@ -100,6 +100,24 @@ Import Attributes syntax is supported in TypeScript >= 5.3, but you can replace

ESLint is not supported Import Attributes syntax yet, but you can use [`@babel/eslint-parser`](https://www.npmjs.com/package/@babel/eslint-parser) or [`@typescript-eslint/parser`](https://typescript-eslint.io/packages/parser/).

```js
// eslint.config.js
import parser from '@babel/eslint-parser'

export default [
{
// ...
languageOptions: {
parser,
parserOptions: {
requireConfigFile: false,
babelOptions: { parserOpts: { plugins: ['importAttributes'] } },
},
},
},
]
```

## Options

Refer to [docs](https://jsr.io/@unplugin/macros/doc/api/~/Options).
Expand Down
21 changes: 16 additions & 5 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { sxzz } from '@sxzz/eslint-config'
export default sxzz([
{
ignores: ['README.md'],
import parser from '@babel/eslint-parser'
import { GLOB_JS, sxzz } from '@sxzz/eslint-config'

export default sxzz({
files: [GLOB_JS],
languageOptions: {
parser,
parserOptions: {
requireConfigFile: false,
babelOptions: {
parserOpts: {
plugins: ['importAttributes'],
},
},
},
},
])
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@
"vite-node": "^2.0.5"
},
"devDependencies": {
"@babel/eslint-parser": "^7.25.1",
"@babel/types": "^7.25.2",
"@sxzz/eslint-config": "^3.17.1",
"@sxzz/eslint-config": "^3.17.2",
"@sxzz/prettier-config": "^2.0.2",
"@types/dedent": "^0.7.2",
"@types/node": "^20.16.0",
Expand Down
72 changes: 63 additions & 9 deletions pnpm-lock.yaml

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

0 comments on commit c4dcd85

Please sign in to comment.