Merge pull request #12633 from codyrancher/linter

Adding a custom lint rule to ensure we use v-clean-tooltip instead of v-tooltip directives.
This commit is contained in:
codyrancher 2024-11-25 16:21:48 -07:00 committed by GitHub
commit d413605ca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 4 deletions

View File

@ -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: [
{

View File

@ -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.'
});
}
}
});
}
};

View File

@ -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",

View File

@ -14,8 +14,8 @@
],
"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"
"build:lib": "vue-cli-service build --skip-plugins eslint --target lib --name @rancher/components src/main.ts",
"lint": "vue-cli-service lint --rulesdir ../../eslint-local-rules"
},
"engines": {
"node": ">=20.0.0"