Skip to content

Commit 41e38bb

Browse files
committed
docs: add documentation of createAliasSetting
1 parent 0a0e14c commit 41e38bb

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

packages/eslint-config-standard/README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ An example `.eslintrc.cjs`:
2727
require("@rushstack/eslint-patch/modern-module-resolution")
2828

2929
module.exports = {
30+
root: true,
3031
extends: [
3132
'plugin:vue/vue3-essential',
3233
'@vue/eslint-config-standard'
@@ -36,4 +37,35 @@ module.exports = {
3637

3738
## Aliases
3839

39-
As
40+
By default, none of the built-in rules require you to configure aliases in ESLint.
41+
42+
But if you want to enable some additional rules that need to actually resolve the imported module on the filesystem (e.g. [`import/no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/v2.26.0/docs/rules/no-unresolved.md)) by yourself, you should configure it.
43+
In that case, we provided a helper function to simplify the task.
44+
45+
For example, it is a widely accepted convention to use `@` as an alias to the `src` folder in the Vue ecosystem. To enable this, you can use the following config:
46+
47+
```js
48+
/* eslint-env node */
49+
require('@rushstack/eslint-patch/modern-module-resolution')
50+
51+
const path = require('node:path')
52+
const createAliasSetting = require('@vue/eslint-config-standard/createAliasSetting')
53+
54+
module.exports = {
55+
root: true,
56+
extends: [
57+
'plugin:vue/vue3-essential',
58+
'@vue/eslint-config-standard'
59+
],
60+
rules: {
61+
'import/no-unresolved': 'error'
62+
}
63+
settings: {
64+
...createAliasSetting({
65+
'@': `${path.resolve(__dirname, './src')}`
66+
})
67+
}
68+
}
69+
```
70+
71+
`createAliasSetting` accepts a map of aliases and their corresponding paths, and returns a settings object to be spread in to the `settings` field of the ESLint config.

0 commit comments

Comments
 (0)