-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a custom lint rule to ensure we use v-clean-tooltip instead of v-tooltip directives. #12633
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.' | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the CI that ran on this PR you can see that we already do a separate lint run https://github.com/rancher/dashboard/actions/runs/11963269493/job/33353388233?pr=12633 The lint run that was done at build time would fail because it seemed to change the working directory and couldn't find the new custom lint rules. I didn't see a point in running the lint rules twice. |
||
"lint": "vue-cli-service lint --rulesdir ../../eslint-local-rules" | ||
}, | ||
"engines": { | ||
"node": ">=20.0.0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if we can specify
rulesdir
ineslintrc
instead of with a cli flag?My assumption is that it's best to stick with the approach in this PR, but my curiousity was piqued when I found some old conversations that suggests eslint deprecating the usage of
ruledir
and recommendingeslint-plugin-rulesdir
as the preferred approach12. I'm guessing that this never materialized in any meaningful way, seeing how we are usingrulesdir
today.Footnotes
https://github.com/eslint/eslint/issues/2715 ↩
https://github.com/eslint/eslint/issues/8769 ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I'll give it a try.
I will note that I also came across rulesdir being deprecated and that this version using --rulesdir was going to be easiest to port when we upgrade eslint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot specify
rulesdir
ineslintrc
.It failed with
![image](https://private-user-images.githubusercontent.com/55104481/389615588-1fe2dfff-402f-4ffe-bd41-3a34aba4d635.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MjY0MTgsIm5iZiI6MTczOTgyNjExOCwicGF0aCI6Ii81NTEwNDQ4MS8zODk2MTU1ODgtMWZlMmRmZmYtNDAyZi00ZmZlLWJkNDEtM2EzNGFiYTRkNjM1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDIxMDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVhMTZkOTc4NGNhOTQxZjY4NjAxNDJjOTYyZjI2MzQ4NjE0ZDJhNGNhODY2YzM2ZjM0NmMxNDUxZmI5MWYzZWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.365iFPX4ljHG8zjRyTY69m6VFNTBGeZdaDPOD9LFd_M)
Which lead me to go look at the config-validator code and there isn't a
rulesdir
option.https://github.com/eslint/eslintrc/blob/v0.4.3/conf/config-schema.js
When we upgrade eslint we will likely want to switch from
--rulesdir
to--plugin
which will cause us to create one extra file to create the plugin with all of our rules. https://eslint.org/docs/latest/use/command-line-interface#--plugin