Skip to content
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

chore(eslint): update eslint no-unused-vars rules #9028

Merged
merged 3 commits into from
Oct 20, 2023

Conversation

Alfred-Skyblue
Copy link
Member

@Alfred-Skyblue Alfred-Skyblue commented Aug 23, 2023

We have excluded the no-unused-vars rule for TypeScript (.ts) files in our existing ESLint configuration, as TypeScript inherently checks for unused variables. However, if we don't configure this rule, ESLint won't perform the no-unused-vars check for TypeScript files. Nevertheless, we do need to enable this rule for JavaScript (.js) files to ensure that variables defined in JavaScript files are also being utilized.

-    'no-unused-vars': [
-      'error',
-      // we are only using this rule to check for unused arguments since TS
-      // catches unused variables but not args.
-      { varsIgnorePattern: '.*', args: 'none' }
-    ],

+    {
+      files: ['*.js'],
+      rules: {
+        // We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
+        'no-unused-vars': ['error', { vars: 'all', args: 'none' }]
+      }
+    },

@github-actions
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 85.8 kB 32.6 kB 29.5 kB
vue.global.prod.js 132 kB 49.3 kB 44.3 kB

Usages

Name Size Gzip Brotli
createApp 47.9 kB 18.8 kB 17.2 kB
createSSRApp 50.6 kB 19.9 kB 18.2 kB
defineCustomElement 50.3 kB 19.6 kB 17.9 kB
overall 61.2 kB 23.7 kB 21.6 kB

Copy link
Member

@sxzz sxzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, but we don't think this change is necessary. Keeping both ESLint and TypeScript at the same time obviously won't affect anything, but it can better alert us to problems in the code.

@sxzz sxzz closed this Aug 31, 2023
@Alfred-Skyblue
Copy link
Member Author

Alfred-Skyblue commented Aug 31, 2023

However, it override the inspection of JS files, causing unused imports in JS not to trigger errors. Additionally, this rule doesn't take effect within TS files. As a result, unused imports readFileSync in our build.js are not being flagged as errors.

@sxzz sxzz reopened this Sep 1, 2023
@sxzz
Copy link
Member

sxzz commented Sep 1, 2023

Then we need to lint both JS and TS files.

@sxzz sxzz added 🧹 p1-chore Priority 1: this doesn't change code behavior. scope: infra labels Sep 1, 2023
@Alfred-Skyblue
Copy link
Member Author

Alfred-Skyblue commented Sep 1, 2023

In our current ESLint rules, we have enabled varsIgnorePattern: '.*', which effectively suppresses warnings for all unused variables, and args: 'none', which also suppresses warnings for all unused function parameters. In practice, these two configurations completely disable their respective functionalities. Enabling them would result in numerous errors in TypeScript files, as demonstrated below:

11801693558634_ pic

Based on the above, I believe we should only apply these checks to JavaScript files.

.eslintrc.cjs Show resolved Hide resolved
@sxzz sxzz added the ready to merge The PR is ready to be merged. label Sep 2, 2023
@yyx990803 yyx990803 merged commit aacb66d into vuejs:main Oct 20, 2023
11 checks passed
@Alfred-Skyblue Alfred-Skyblue deleted the chore-eslint-rules branch October 20, 2023 10:00
lumozx pushed a commit to lumozx/core that referenced this pull request Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior. ready to merge The PR is ready to be merged. scope: infra
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants