Skip to content

Commit

Permalink
docs: add documentation of createAliasSetting
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang committed Jul 21, 2022
1 parent 0a0e14c commit 41e38bb
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/eslint-config-standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ An example `.eslintrc.cjs`:
require("@rushstack/eslint-patch/modern-module-resolution")

module.exports = {
root: true,
extends: [
'plugin:vue/vue3-essential',
'@vue/eslint-config-standard'
Expand All @@ -36,4 +37,35 @@ module.exports = {

## Aliases

As
By default, none of the built-in rules require you to configure aliases in ESLint.

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.
In that case, we provided a helper function to simplify the task.

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:

```js
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

const path = require('node:path')
const createAliasSetting = require('@vue/eslint-config-standard/createAliasSetting')

module.exports = {
root: true,
extends: [
'plugin:vue/vue3-essential',
'@vue/eslint-config-standard'
],
rules: {
'import/no-unresolved': 'error'
}
settings: {
...createAliasSetting({
'@': `${path.resolve(__dirname, './src')}`
})
}
}
```

`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 comments on commit 41e38bb

Please sign in to comment.