Skip to content

Commit

Permalink
use the typescript variant for the local linting rule
Browse files Browse the repository at this point in the history
referring to https://github.com/cletusw/eslint-plugin-local-rules?tab=readme-ov-file#usage-typescript
- move configuration to separate subdirectory
- move rule file to separate subdirectory
  • Loading branch information
mahula committed Feb 13, 2024
1 parent 5e486dc commit de75bfe
Show file tree
Hide file tree
Showing 3 changed files with 17,019 additions and 19,959 deletions.
18 changes: 18 additions & 0 deletions presenter/eslint-local-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import tsNode from 'ts-node'

let defaultExport

const loadRules = async () => {
tsNode.register({
transpileOnly: true,
compilerOptions: {
module: 'commonjs',
},
})

const rulesModule = await import('./rules')
defaultExport = rulesModule.default
}

loadRules()
export default defaultExport
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint import/no-commonjs: 0 */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const utils = require('./node_modules/eslint-plugin-vue/lib/utils')
import utils from './node_modules/eslint-plugin-vue/lib/utils'

function getName(attribute) {
import type { Rule } from 'eslint'

function getName(attribute: any) {
if (!attribute.directive) {
return attribute.key.name
}
Expand All @@ -17,20 +18,19 @@ function getName(attribute) {
return null
}

function getValue(attribute) {
function getValue(attribute: any ) {
return attribute.value.value
}

module.exports = {
export default {
'href-pattern': {
meta: {
type: 'problem',
docs: {
description: 'Enforce href attribute values to start with "/" or "https://" in .vue files',
},
fixable: null,
fixable: undefined,
schema: [],
context: ['vue'],
messages: {
invalidHrefValue:
'Invalid href value: "{{hrefValue}}". In this project href values must start with "/" or "https://".',
Expand All @@ -39,7 +39,7 @@ module.exports = {
create(context) {
return utils.defineTemplateBodyVisitor(context, {
VStartTag() {},
VAttribute(node) {
VAttribute(node: any) {
const name = getName(node)
if (name == null) {
return
Expand All @@ -65,4 +65,4 @@ module.exports = {
})
},
},
}
} satisfies Record<string, Rule.RuleModule>
Loading

0 comments on commit de75bfe

Please sign in to comment.