Skip to content

Commit f88061b

Browse files
committed
Docs: add document for version-specific URLs
1 parent 3f17cf4 commit f88061b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Diff for: docs/rules/require-meta-docs-url.md

+44
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,50 @@ module.exports = {
101101

102102
```
103103

104+
## Version specific URL
105+
106+
If you want to enforce version-specific URLs, it's feasible easily with `.eslintrc.js` and `npm version <type>` script.
107+
For example:
108+
109+
**.eslintrc.js**:
110+
111+
```js
112+
"use strict"
113+
114+
const version = require("./package.json").version
115+
116+
module.exports = {
117+
plugins: ["eslint-plugin"],
118+
// ... leaving out ...
119+
rules: {
120+
"eslint-plugin/require-meta-docs-url": ["error", {
121+
pattern: `path/to/v${version}/docs/rules/{{name}}.md`,
122+
}],
123+
}
124+
}
125+
```
126+
127+
**package.json**:
128+
129+
```json
130+
{
131+
"version": "1.0.0",
132+
"scripts": {
133+
"pretest": "eslint .",
134+
"test": "... leaving out ...",
135+
"preversion": "npm test",
136+
"version": "eslint . --fix && git add ."
137+
},
138+
// ... leaving out ...
139+
}
140+
```
141+
142+
Then `npm version <type>` command will update every rule to the new version's URL.
143+
144+
> npm runs `preversion` script on the current version, runs `version` script on the new version, and commits and makes a tag.
145+
>
146+
> Further reading: https://docs.npmjs.com/cli/version
147+
104148
## When Not To Use It
105149

106150
If you do not plan to provide rule's documentation in website, you can turn off this rule.

0 commit comments

Comments
 (0)