Skip to content

Commit 2f22b24

Browse files
author
Vibe Bot
committed
Add tests for S7759 based on ruling analysis
Add test cases derived from real-world polyfill patterns found during ruling analysis: - Chained ternary polyfill (performance.now || Date.now || fallback) - Class static property with ternary polyfill - Export const with Date.now polyfill The implementation correctly handles all 48 ruling entries with no mismatches between expected and actual behavior.
1 parent 3366c31 commit 2f22b24

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/jsts/src/rules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ SonarJS uses some rules are not shipped in this ESLint plugin to avoid duplicati
557557
| [S7756](https://sonarsource.github.io/rspec/#/rspec/S7756/javascript) | [unicorn/prefer-blob-reading-methods](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-blob-reading-methods.md) |
558558
| [S7757](https://sonarsource.github.io/rspec/#/rspec/S7757/javascript) | [unicorn/prefer-class-fields](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-class-fields.md) |
559559
| [S7758](https://sonarsource.github.io/rspec/#/rspec/S7758/javascript) | [unicorn/prefer-code-point](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-code-point.md) |
560-
| [S7759](https://sonarsource.github.io/rspec/#/rspec/S7759/javascript) | [unicorn/prefer-date-now](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-date-now.md) |
561560
| [S7760](https://sonarsource.github.io/rspec/#/rspec/S7760/javascript) | [unicorn/prefer-default-parameters](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-default-parameters.md) |
562561
| [S7761](https://sonarsource.github.io/rspec/#/rspec/S7761/javascript) | [unicorn/prefer-dom-node-dataset](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-dom-node-dataset.md) |
563562
| [S7762](https://sonarsource.github.io/rspec/#/rspec/S7762/javascript) | [unicorn/prefer-dom-node-remove](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-dom-node-remove.md) |
@@ -659,6 +658,7 @@ The following rules are used in SonarJS but not available in this ESLint plugin.
659658
| [S7727](https://sonarsource.github.io/rspec/#/rspec/S7727/javascript) | [unicorn/no-array-callback-reference](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/no-array-callback-reference.md) |
660659
| [S7728](https://sonarsource.github.io/rspec/#/rspec/S7728/javascript) | [unicorn/no-array-for-each](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/no-array-for-each.md) |
661660
| [S7755](https://sonarsource.github.io/rspec/#/rspec/S7755/javascript) | [unicorn/prefer-at](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-at.md) |
661+
| [S7759](https://sonarsource.github.io/rspec/#/rspec/S7759/javascript) | [unicorn/prefer-date-now](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-date-now.md) |
662662
| [S7763](https://sonarsource.github.io/rspec/#/rspec/S7763/javascript) | [unicorn/prefer-export-from](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-export-from.md) |
663663

664664
<!--- end decorated rules -->

packages/jsts/src/rules/S7759/unit.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ describe('S7759', () => {
6666
{
6767
code: `var timestamp = Date.now();`,
6868
},
69+
70+
// Chained ternary polyfill (from TypeScript real-world usage)
71+
{
72+
code: `var timestamp = typeof performance !== "undefined" && performance.now ? function() { return performance.now(); } : Date.now ? Date.now : function() { return +(new Date()); };`,
73+
},
74+
75+
// Class static property with ternary polyfill (from rxjs real-world usage)
76+
{
77+
code: `class Scheduler { static now = Date.now ? Date.now : () => +new Date(); }`,
78+
},
79+
80+
// Export with Date.now polyfill (from qunit real-world usage)
81+
{
82+
code: `export const now = Date.now || function() { return new Date().getTime(); };`,
83+
},
6984
],
7085
invalid: [
7186
// Direct usage without polyfill pattern should still report

0 commit comments

Comments
 (0)