Skip to content

Commit

Permalink
Adding a custom lint rule to ensure we use v-clean-tooltip instead of…
Browse files Browse the repository at this point in the history
… v-tooltip directives.
  • Loading branch information
codyrancher committed Nov 21, 2024
1 parent 50f7916 commit 1542da0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ module.exports = {
'vue/one-component-per-file': 'off',
'vue/no-deprecated-slot-attribute': 'off',
'vue/require-explicit-emits': 'error',
'vue/v-on-event-hyphenation': 'off'
'vue/v-on-event-hyphenation': 'off',

// Locally defined rules, you can find these defined in the `eslint-local-rules` directory.
'v-clean-tooltip': 'error',
},
overrides: [
{
Expand Down
33 changes: 33 additions & 0 deletions eslint-local-rules/v-clean-tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Currently loading these rules with the --rulesdir argument. In the future we could make use of `eslint-plugin-local-rules`.
const vueUtils = require('eslint-plugin-vue/lib/utils');

module.exports = {
meta: {
type: 'problem',
docs: { description: 'We want to use `v-clean-tooltip` instead of `v-tooltip` in most all areas to avoid XSS exploits.' },
schema: [],
},
create(context) {
return vueUtils.defineTemplateBodyVisitor(context, {
VAttribute(node) {
// v-tooltip is a VDirectiveKey
if (node?.key?.type !== 'VDirectiveKey') {
return;
}

// v-tooltip is also a VIdentifier
if (node.key.name.type !== 'VIdentifier') {
return;
}

if (node.key.name.name === 'tooltip') {
context.report({
node: node.key,
loc: node.loc,
message: 'We want to use `v-clean-tooltip` instead of `v-tooltip` in most all areas to avoid XSS exploits.'
});
}
}
});
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"serve-pkgs": "./shell/scripts/serve-pkgs",
"publish-shell-reset-reg": "cd shell && npm publish",
"clean": "./shell/scripts/clean",
"lint": "./node_modules/.bin/eslint --max-warnings 0 --ext .js,.ts,.vue .",
"lint": "./node_modules/.bin/eslint --rulesdir ./eslint-local-rules --max-warnings 0 --ext .js,.ts,.vue .",
"lint:lib": "cd pkg/rancher-components && yarn lint",
"lint-l10n": "./node_modules/.bin/yamllint ./shell/assets/translations",
"test": "NODE_OPTIONS=--max_old_space_size=8192 jest --watch",
Expand Down
2 changes: 1 addition & 1 deletion pkg/rancher-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"types": "./types/index.d.ts",
"scripts": {
"build:lib": "vue-cli-service build --target lib --name @rancher/components src/main.ts",
"lint": "vue-cli-service lint"
"lint": "vue-cli-service lint --rulesdir ../../eslint-local-rules"
},
"engines": {
"node": ">=20.0.0"
Expand Down

0 comments on commit 1542da0

Please sign in to comment.