Skip to content

Commit

Permalink
Chores: Add JSDoc type checking with TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jun 12, 2020
1 parent 6f8acee commit 33c898d
Show file tree
Hide file tree
Showing 186 changed files with 5,327 additions and 2,111 deletions.
18 changes: 0 additions & 18 deletions .eslintrc.js
Expand Up @@ -37,24 +37,6 @@ module.exports = {
'dot-notation': 'error'
},
overrides: [
// Introduce prettier. but ignore files to avoid conflicts with PR.
{
files: [
// https://github.com/vuejs/eslint-plugin-vue/pull/819
'lib/rules/attributes-order.js',
'tests/lib/rules/attributes-order.js'
],
extends: [
'plugin:eslint-plugin/recommended',
'plugin:vue-libs/recommended'
],
rules: {
'prettier/prettier': 'off',

'rest-spread-spacing': 'error',
'no-mixed-operators': 'error'
}
},
{
files: ['lib/rules/*.js'],
rules: {
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Expand Up @@ -7,5 +7,6 @@
"javascript",
"javascriptreact",
{ "language": "vue", "autoFix": true }
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
24 changes: 13 additions & 11 deletions lib/processor.js
Expand Up @@ -13,6 +13,7 @@
*/

module.exports = {
/** @param {string} code */
preprocess(code) {
return [code]
},
Expand All @@ -34,6 +35,7 @@ module.exports = {
disableRuleKeys: new Map()
}
}
/** @type {string[]} */
const usedDisableDirectiveKeys = []
/** @type {Map<string,LintMessage>} */
const unusedDisableDirectiveReports = new Map()
Expand Down Expand Up @@ -88,15 +90,15 @@ module.exports = {
if (state.line.disableAllKeys.size) {
disableDirectiveKeys.push(...state.line.disableAllKeys)
}
if (state.block.disableRuleKeys.has(message.ruleId)) {
disableDirectiveKeys.push(
...state.block.disableRuleKeys.get(message.ruleId)
)
}
if (state.line.disableRuleKeys.has(message.ruleId)) {
disableDirectiveKeys.push(
...state.line.disableRuleKeys.get(message.ruleId)
)
if (message.ruleId) {
const block = state.block.disableRuleKeys.get(message.ruleId)
if (block) {
disableDirectiveKeys.push(...block)
}
const line = state.line.disableRuleKeys.get(message.ruleId)
if (line) {
disableDirectiveKeys.push(...line)
}
}

if (disableDirectiveKeys.length) {
Expand Down Expand Up @@ -153,8 +155,8 @@ function messageToKey(message) {

/**
* Compares the locations of two objects in a source file
* @param {{line: number, column: number}} itemA The first object
* @param {{line: number, column: number}} itemB The second object
* @param {Position} itemA The first object
* @param {Position} itemB The second object
* @returns {number} A value less than 1 if itemA appears before itemB in the source file, greater than 1 if
* itemA appears after itemB in the source file, or 0 if itemA and itemB have the same location.
*/
Expand Down
1 change: 1 addition & 0 deletions lib/rules/array-bracket-spacing.js
Expand Up @@ -7,6 +7,7 @@ const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
module.exports = wrapCoreRule(
// @ts-ignore
require('eslint/lib/rules/array-bracket-spacing'),
{ skipDynamicArguments: true }
)
5 changes: 4 additions & 1 deletion lib/rules/arrow-spacing.js
Expand Up @@ -6,4 +6,7 @@
const { wrapCoreRule } = require('../utils')

// eslint-disable-next-line
module.exports = wrapCoreRule(require('eslint/lib/rules/arrow-spacing'))
module.exports = wrapCoreRule(
// @ts-ignore
require('eslint/lib/rules/arrow-spacing')
)
13 changes: 11 additions & 2 deletions lib/rules/attribute-hyphenation.js
Expand Up @@ -45,7 +45,7 @@ module.exports = {
}
]
},

/** @param {RuleContext} context */
create(context) {
const sourceCode = context.getSourceCode()
const option = context.options[0]
Expand All @@ -61,6 +61,10 @@ module.exports = {
useHyphenated ? 'kebab-case' : 'camelCase'
)

/**
* @param {VDirective | VAttribute} node
* @param {string} name
*/
function reportIssue(node, name) {
const text = sourceCode.getText(node.key)

Expand All @@ -78,6 +82,9 @@ module.exports = {
})
}

/**
* @param {string} value
*/
function isIgnoredAttribute(value) {
const isIgnored = ignoredAttributes.some((attr) => {
return value.indexOf(attr) !== -1
Expand All @@ -101,7 +108,9 @@ module.exports = {
const name = !node.directive
? node.key.rawName
: node.key.name.name === 'bind'
? node.key.argument && node.key.argument.rawName
? node.key.argument &&
node.key.argument.type === 'VIdentifier' &&
node.key.argument.rawName
: /* otherwise */ false
if (!name || isIgnoredAttribute(name)) return

Expand Down

0 comments on commit 33c898d

Please sign in to comment.