Skip to content

feat: add restrict-plus-operands#129

Merged
yokuze merged 2 commits intosilvermine:masterfrom
leviFrosty:restrict-plus-operands
Oct 30, 2025
Merged

feat: add restrict-plus-operands#129
yokuze merged 2 commits intosilvermine:masterfrom
leviFrosty:restrict-plus-operands

Conversation

@leviFrosty
Copy link
Contributor

@leviFrosty
Copy link
Contributor Author

Will fix CI

@leviFrosty
Copy link
Contributor Author

I do not like this change for various reasons... The only thing I can think to do is turn this into a mini mono-repo with a nested project within ./test-cases that installs the root eslint-config package, sets up its' own tsconfigs, tooling, etc. Then update CI to call this test-cases project within the workspace.

Otherwise, as it stands users of this package will get this dependencies installed automatically, which isn't ideal because some node-only projects will not want vue as a dev dep.

I think I'll probably refactor this, but just wanted to get out a working version and then see what you thought @onebytegone

@@ -1,57 +1,60 @@
{
"name": "@silvermine/eslint-config",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Formats to 3 spaces (like some other repos)... Not really supposed to be included in this PR but I added here anyway

"typescript": "5.8.3",
"@silvermine/typescript-config": "github:silvermine/typescript-config#ea8b79237aee970a15ab85beedf8e524478ef671",
"vue": "3.5.18",
"@vue/tsconfig": "0.7.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notable changes lines 48-50

@leviFrosty
Copy link
Contributor Author

This add restrict-plus-operands is the first eslint plugin rule that we have enabled that requires a typescript project config available. It needs access to type information in order to give more powerful linting options.

See https://typescript-eslint.io/getting-started/typed-linting/

@yokuze
Copy link
Contributor

yokuze commented Oct 23, 2025

I do not like this change for various reasons... The only thing I can think to do is turn this into a mini mono-repo with a nested project within ./test-cases that installs the root eslint-config package, sets up its' own tsconfigs, tooling, etc. Then update CI to call this test-cases project within the workspace.

Otherwise, as it stands users of this package will get this dependencies installed automatically, which isn't ideal because some node-only projects will not want vue as a dev dep.

I think I'll probably refactor this, but just wanted to get out a working version and then see what you thought @onebytegone

I haven't looked at this closely enough to understand the overarching issue that you're suggesting the monorepo for, but just wanted to point out that any package that uses this package shouldn't get Vue because it's a devDependency, in case that helps.

@leviFrosty
Copy link
Contributor Author

I do not like this change for various reasons... The only thing I can think to do is turn this into a mini mono-repo with a nested project within ./test-cases that installs the root eslint-config package, sets up its' own tsconfigs, tooling, etc. Then update CI to call this test-cases project within the workspace.
Otherwise, as it stands users of this package will get this dependencies installed automatically, which isn't ideal because some node-only projects will not want vue as a dev dep.
I think I'll probably refactor this, but just wanted to get out a working version and then see what you thought @onebytegone

I haven't looked at this closely enough to understand the overarching issue that you're suggesting the monorepo for, but just wanted to point out that any package that uses this package shouldn't get Vue because it's a devDependency, in case that helps.

Honestly kind of blanked and forgot devDeps don't get inherited. Think this PR should be OK to merge as is then?

@leviFrosty
Copy link
Contributor Author

leviFrosty commented Oct 23, 2025

Consumers of this update will need to add this to their eslint config if they do not already have it.

Don't know how we'd want to document this breaking change -- but notable here.

{
    // eslint.config.js
    ...
    files: [ '**/*.ts' ],
    languageOptions: {
       parserOptions: {
          project: 'tsconfig.json', // <----- THIS LINE
       },
    },
    ...
}

@leviFrosty leviFrosty force-pushed the restrict-plus-operands branch 3 times, most recently from 2a18d14 to 1d01d40 Compare October 27, 2025 15:20
@leviFrosty
Copy link
Contributor Author

Alright, I've added the readme.md examples as well as the update to the commit message, please have a look over them.
Hopefully they're concise enough to get across the point without omitting too many details.

Should be good to merge now @yokuze

README.md Outdated
...config,
{
files: [ '**/*.ts' ],
...config,
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the target of the ...config spread moved from the array to an object that's surrounding all of the config properties. Also, there's a syntax error: The { ...typescript block is nested within that object, but without a key.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which makes me think that with these extra levels of nesting the spread syntax approach is just a bit too onerous now.

Could you look at how we may be able to use ESLint's extend property instead? Maybe something like:

[
   {
      files: [ '**/*.ts' ],
      languageOptions: {
         parserOptions: {
            project: './tsconfig.node.json',
         },
      },
      extends: [ typescript ],
   }
]

? Not sure - you'd have to check that ESLint merges the config keys/values in the way that would make that work without blowing away the other languageOptions, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, sorry about misaligned spread syntax. Resolved that issue on latest change. Also simplified the example as, like you said, it's a bit onerous.

Tested on another large repo with my forked commit hash. Tested working as presented in this example as well as a few other configuration options that are more involved.

Regarding the extends key, it's been deprecated/removed in v9, only enabled via some compat functions. Now that this example has been simplified to only highlight the necessary changes, I think we'll be fine to leave as-is for now and return to this issue when we upgrade to eslint v9.

Oops! Something went wrong! :(

ESLint: 8.57.1

A config object is using the "extends" key, which is not supported in flat config system.

Instead of "extends", you can include config objects that you'd like to extend from directly in the flat config array.

Please see the following page for more information:
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-and-shareable-configs

README.md Outdated
Notice that we must specify the `project` property within `languageOptions.parserOptions`
to enable TypeScript strongly typed linting.

Below is an example of using Vue 3 with TypeScript:
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a "Vue Support" heading below - it seems like this belongs there, especially now that it's required config for Vue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching. I moved all of the Vue related config notes within the Vue subheading.

README.md Outdated
vue = require('@silvermine/eslint-config/partials/vue');

module.exports = [
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue here with the top-level { }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved this as well. Thanks

@leviFrosty leviFrosty force-pushed the restrict-plus-operands branch from 1d01d40 to 7d51c9b Compare October 28, 2025 15:34
This enables strongly typed checking within the current project. Consumers of this repo
will need to be sure they pass languageOptions.parserOptions.project, which points
to their tsconfig file to enable type checking rules.
@leviFrosty leviFrosty force-pushed the restrict-plus-operands branch from 7d51c9b to 693ba3e Compare October 28, 2025 16:10
Copy link
Contributor

@yokuze yokuze left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@yokuze yokuze merged commit 8476c65 into silvermine:master Oct 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants