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

Resolve JS-81- Options Schemas required for ESLint v9 #4679

Merged
merged 3 commits into from
May 3, 2024

Conversation

ericmorand-sonarsource
Copy link
Contributor

@ericmorand-sonarsource ericmorand-sonarsource commented May 2, 2024

Just testing from the CI to prevent my computer from crashing.

Fixes JS-81

@ericmorand-sonarsource ericmorand-sonarsource force-pushed the JS-81 branch 12 times, most recently from 1ede563 to 49ff037 Compare May 3, 2024 09:37
@ericmorand-sonarsource ericmorand-sonarsource changed the title JS-81: WIP Resolve JS-81- Options Schemas required for ESLint v9 May 3, 2024
@ericmorand-sonarsource ericmorand-sonarsource force-pushed the JS-81 branch 5 times, most recently from 10a4d8a to 3f86fda Compare May 3, 2024 10:35
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, there was no test at all for this one.

Copy link
Contributor

@zglicz zglicz left a comment

Choose a reason for hiding this comment

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

Talked offline about the typing - very slick.
The Java class serve no purpose, except for storing the default values. Except for that, they could be autogenerated. If we were to move these definitions into js/ts, we could fully auto generate them and remove the need for the additional tests to test passing of simple values....

All in all looks good and a very positive change!
lgtmacro

string?,
];

export const rule: RuleModule<Options> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, perhaps we could introduce a new type, when the rule depends on the "SONAR_RUNTIME" check and then have the enum be added on implicitly?

packages/jsts/src/rules/S107/rule.ts Outdated Show resolved Hide resolved
packages/jsts/src/rules/S1541/rule.ts Outdated Show resolved Hide resolved
@@ -25,21 +25,36 @@ import { TSESTree } from '@typescript-eslint/utils';
import { getMainFunctionTokenLocation } from 'eslint-plugin-sonarjs/lib/utils/locations';
import { SONAR_RUNTIME } from '../../linter/parameters';
import { RuleContext, toEncodedMessage } from '../helpers';
import type { RuleModule } from '../../../../shared/src/types/rule';

const DEFAULT_THRESHOLD = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

I do hope so, that the Java default is the same as this default... But in all seriousness perhaps this default could be further integrated into the js/ts rule? Perhaps in the meta field somewhere? As we discussed with @ericmorand-sonarsource, the default parameters are currently stored on the Java side, which unnecessarily scatters the logic into the boilerplate Java file... Perhaps a Jira task for the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely agree.

packages/shared/src/types/rule.ts Outdated Show resolved Hide resolved
Copy link

sonarqube-next bot commented May 3, 2024

Quality Gate failed Quality Gate failed

Failed conditions
5.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube

@saberduck saberduck merged commit 3ac1ccb into SonarSource:master May 3, 2024
13 of 14 checks passed
@ericmorand-sonarsource ericmorand-sonarsource deleted the JS-81 branch May 3, 2024 15:39
type RuleModuleSchema<Options extends RuleOptions> =
| {
type: 'object';
properties: { [key in keyof Options[0]]: JSONSchema.JSONSchema4 };
Copy link
Contributor

Choose a reason for hiding this comment

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

@ericmorand-sonarsource - I was looking through this and have a q: What happens if the RuleOptions is only [SonarRuntime], what would be this allowed this "key in keyof Options[0]" ?

Copy link
Contributor Author

@ericmorand-sonarsource ericmorand-sonarsource May 6, 2024

Choose a reason for hiding this comment

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

Probably not, we would have to set schema to:

schema: [
      {
        type: 'object',
        properties: {},
      },
      {
        type: 'string',
        enum: ['sonar-runtime']
      }
    ]

Which is what we have to put as a minimal schema, anyway, since we can't know if a rule will eventually have options.

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.

3 participants