Skip to content

Commit b33c708

Browse files
authored
Chores: Add JSDoc type checking with TypeScript (#1206)
* Chores: Add JSDoc type checking with TypeScript * update * update * update guide
1 parent 6f8acee commit b33c708

File tree

171 files changed

+5282
-2075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+5282
-2075
lines changed

Diff for: .eslintrc.js

-18
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ module.exports = {
3737
'dot-notation': 'error'
3838
},
3939
overrides: [
40-
// Introduce prettier. but ignore files to avoid conflicts with PR.
41-
{
42-
files: [
43-
// https://github.com/vuejs/eslint-plugin-vue/pull/819
44-
'lib/rules/attributes-order.js',
45-
'tests/lib/rules/attributes-order.js'
46-
],
47-
extends: [
48-
'plugin:eslint-plugin/recommended',
49-
'plugin:vue-libs/recommended'
50-
],
51-
rules: {
52-
'prettier/prettier': 'off',
53-
54-
'rest-spread-spacing': 'error',
55-
'no-mixed-operators': 'error'
56-
}
57-
},
5840
{
5941
files: ['lib/rules/*.js'],
6042
rules: {

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
yarn.lock
99
yarn-error.log
1010
docs/.vuepress/dist
11+
typings/eslint/lib/rules

Diff for: .vscode/settings.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"eslint.validate": [
77
"javascript",
88
"javascriptreact",
9-
{ "language": "vue", "autoFix": true }
10-
]
9+
"vue"
10+
],
11+
"typescript.tsdk": "node_modules/typescript/lib"
1112
}

Diff for: docs/developer-guide/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ Check out an [example rule](https://github.com/vuejs/eslint-plugin-vue/blob/mast
4747
Please be aware that regarding what kind of code examples you'll write in tests, you'll have to accordingly setup the parser in `RuleTester` (you can do it on per test case basis though). [See an example here](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/attribute-hyphenation.js#L19)
4848

4949
If you'll stuck, remember there are plenty of rules you can learn from already, and if you can't find the right solution - don't hesitate to reach out in issues. We're happy to help!
50+
51+
## :white_check_mark: JSDoc type checking with TypeScript
52+
53+
We have type checking enabled via TypeScript and JSDoc.
54+
The command to perform type checking is: `npm run tsc`
55+
56+
This is just to help you write the rules, not to do strict type checking. If you find it difficult to resolve type checking warnings, feel free to suppress warnings using the `// @ts-nocheck` and `// @ts-ignore` comment.

Diff for: lib/processor.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
module.exports = {
16+
/** @param {string} code */
1617
preprocess(code) {
1718
return [code]
1819
},
@@ -34,6 +35,7 @@ module.exports = {
3435
disableRuleKeys: new Map()
3536
}
3637
}
38+
/** @type {string[]} */
3739
const usedDisableDirectiveKeys = []
3840
/** @type {Map<string,LintMessage>} */
3941
const unusedDisableDirectiveReports = new Map()
@@ -88,15 +90,15 @@ module.exports = {
8890
if (state.line.disableAllKeys.size) {
8991
disableDirectiveKeys.push(...state.line.disableAllKeys)
9092
}
91-
if (state.block.disableRuleKeys.has(message.ruleId)) {
92-
disableDirectiveKeys.push(
93-
...state.block.disableRuleKeys.get(message.ruleId)
94-
)
95-
}
96-
if (state.line.disableRuleKeys.has(message.ruleId)) {
97-
disableDirectiveKeys.push(
98-
...state.line.disableRuleKeys.get(message.ruleId)
99-
)
93+
if (message.ruleId) {
94+
const block = state.block.disableRuleKeys.get(message.ruleId)
95+
if (block) {
96+
disableDirectiveKeys.push(...block)
97+
}
98+
const line = state.line.disableRuleKeys.get(message.ruleId)
99+
if (line) {
100+
disableDirectiveKeys.push(...line)
101+
}
100102
}
101103

102104
if (disableDirectiveKeys.length) {
@@ -153,8 +155,8 @@ function messageToKey(message) {
153155

154156
/**
155157
* Compares the locations of two objects in a source file
156-
* @param {{line: number, column: number}} itemA The first object
157-
* @param {{line: number, column: number}} itemB The second object
158+
* @param {Position} itemA The first object
159+
* @param {Position} itemB The second object
158160
* @returns {number} A value less than 1 if itemA appears before itemB in the source file, greater than 1 if
159161
* itemA appears after itemB in the source file, or 0 if itemA and itemB have the same location.
160162
*/

Diff for: lib/rules/arrow-spacing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
const { wrapCoreRule } = require('../utils')
77

8-
// eslint-disable-next-line
8+
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
99
module.exports = wrapCoreRule(require('eslint/lib/rules/arrow-spacing'))

Diff for: lib/rules/attribute-hyphenation.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
}
4646
]
4747
},
48-
48+
/** @param {RuleContext} context */
4949
create(context) {
5050
const sourceCode = context.getSourceCode()
5151
const option = context.options[0]
@@ -61,6 +61,10 @@ module.exports = {
6161
useHyphenated ? 'kebab-case' : 'camelCase'
6262
)
6363

64+
/**
65+
* @param {VDirective | VAttribute} node
66+
* @param {string} name
67+
*/
6468
function reportIssue(node, name) {
6569
const text = sourceCode.getText(node.key)
6670

@@ -78,6 +82,9 @@ module.exports = {
7882
})
7983
}
8084

85+
/**
86+
* @param {string} value
87+
*/
8188
function isIgnoredAttribute(value) {
8289
const isIgnored = ignoredAttributes.some((attr) => {
8390
return value.indexOf(attr) !== -1
@@ -101,7 +108,9 @@ module.exports = {
101108
const name = !node.directive
102109
? node.key.rawName
103110
: node.key.name.name === 'bind'
104-
? node.key.argument && node.key.argument.rawName
111+
? node.key.argument &&
112+
node.key.argument.type === 'VIdentifier' &&
113+
node.key.argument.rawName
105114
: /* otherwise */ false
106115
if (!name || isIgnoredAttribute(name)) return
107116

0 commit comments

Comments
 (0)