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

[DO NOT REVIEW] Migrate to eslint 9 and flat config #2192

Draft
wants to merge 123 commits into
base: main
Choose a base branch
from

Conversation

matthieu-crouzet
Copy link
Contributor

@matthieu-crouzet matthieu-crouzet commented Sep 23, 2024

Proposed change

Migrate to eslint 9 and flat config

Missing in this PR:

  • Review with the team the config exposed in @o3r/eslint-config
  • Fix errors due to the new config
  • Documentation:
    • Difference of rules between the 2 configs
    • Update global documentation (docs/linter/*)
  • fix ng-add @o3r/eslint-config
  • fix jsdoc/check-examples
  • Bonus: CLI to detect deprecated rules

@matthieu-crouzet matthieu-crouzet changed the title Migrate to eslint 9 and flat config [DO NOT REVIEW] Migrate to eslint 9 and flat config Sep 23, 2024
@@ -42,27 +52,27 @@
*/
private parseCssVariable(name: string, value = ''): CssVariable {
const defaultValue = value.trim();
const res = defaultValue.match(/^var\( *([^,)]*) *(?:, *([^,()]*(\(.*\))?))*\)$/);
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'var(,' and containing many repetitions of ' ,'.

Copilot Autofix AI 1 day ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. This can be achieved by making the sub-expressions more specific and avoiding nested quantifiers.

  • The original regular expression on line 55 is: ^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$
  • We will modify it to: ^var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\(.*\))?))*\s*\)$

This change ensures that the sub-expressions are more specific and reduces the risk of catastrophic backtracking.

Suggested changeset 1
packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
--- a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
+++ b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
@@ -54,3 +54,3 @@
     const defaultValue = value.trim();
-    const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
+    const res = defaultValue.match(/^var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\(.*\))?))*\s*\)$/);
     const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
       do {
-        ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
+        ref = /var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\(.*\))?))*\s*\)/.exec(findRef);
         if (ref) {
EOF
@@ -54,3 +54,3 @@
const defaultValue = value.trim();
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
const res = defaultValue.match(/^var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\(.*\))?))*\s*\)$/);
const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
do {
ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
ref = /var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\(.*\))?))*\s*\)/.exec(findRef);
if (ref) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -42,27 +52,27 @@
*/
private parseCssVariable(name: string, value = ''): CssVariable {
const defaultValue = value.trim();
const res = defaultValue.match(/^var\( *([^,)]*) *(?:, *([^,()]*(\(.*\))?))*\)$/);
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'var(,(' and containing many repetitions of '),('.

Copilot Autofix AI 1 day ago

To fix the problem, we need to modify the regular expression to avoid the use of ambiguous patterns that can cause exponential backtracking. Specifically, we should replace the .* pattern with a more precise pattern that matches the expected characters without causing ambiguity.

  • The original regular expression on line 55 is: ^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$
  • We will replace .* with a more specific pattern that matches any character except for parentheses, commas, and spaces, which are the delimiters in this context.
Suggested changeset 1
packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
--- a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
+++ b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
@@ -54,3 +54,3 @@
     const defaultValue = value.trim();
-    const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
+    const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*\([^()]*\))?)*\)$/);
     const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
       do {
-        ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
+        ref = /var\( *([^),]*) *(?:, *([^(),]*\([^()]*\))?)*\)/.exec(findRef);
         if (ref) {
EOF
@@ -54,3 +54,3 @@
const defaultValue = value.trim();
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*\([^()]*\))?)*\)$/);
const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
do {
ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
ref = /var\( *([^),]*) *(?:, *([^(),]*\([^()]*\))?)*\)/.exec(findRef);
if (ref) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
let findRef = defaultValue;
let ref: RegExpExecArray | null;
const references: Record<string, CssVariable> = {};
do {
ref = /var\( *([^,)]*) *(?:, *([^,()]*(\(.*\))?))*\)/.exec(findRef);
ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'var(,' and containing many repetitions of ' ,'.

Copilot Autofix AI 1 day ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. This can be achieved by making the sub-expressions more specific and avoiding nested quantifiers that can match the same string in multiple ways.

The best way to fix the problem is to rewrite the regular expression to ensure that each part of the pattern is unambiguous. Specifically, we can replace the ambiguous parts with more precise patterns that do not overlap in their matching capabilities.

Suggested changeset 1
packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
--- a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
+++ b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
@@ -54,3 +54,3 @@
     const defaultValue = value.trim();
-    const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
+    const res = defaultValue.match(/^var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\([^)]*\))?))*\s*\)$/);
     const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
       do {
-        ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
+        ref = /var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\([^)]*\))?))*\s*\)/.exec(findRef);
         if (ref) {
EOF
@@ -54,3 +54,3 @@
const defaultValue = value.trim();
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
const res = defaultValue.match(/^var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\([^)]*\))?))*\s*\)$/);
const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
do {
ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
ref = /var\(\s*([^),\s]+)\s*(?:,\s*([^(),\s]+(?:\([^)]*\))?))*\s*\)/.exec(findRef);
if (ref) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
let findRef = defaultValue;
let ref: RegExpExecArray | null;
const references: Record<string, CssVariable> = {};
do {
ref = /var\( *([^,)]*) *(?:, *([^,()]*(\(.*\))?))*\)/.exec(findRef);
ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'var(,(' and containing many repetitions of '),('.

Copilot Autofix AI 1 day ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. Specifically, we should replace the .* pattern with a more specific pattern that avoids matching in multiple ways. In this case, we can replace .* with [^()]* to ensure that the pattern matches any character except parentheses, which are the delimiters in the context of this regular expression.

  • Modify the regular expression on line 55 and line 66 to replace .* with [^()]*.
  • Ensure that the new pattern maintains the existing functionality of matching CSS variable references.
Suggested changeset 1
packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
--- a/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
+++ b/packages/@o3r/styling/builders/style-extractor/helpers/css-variable.extractor.ts
@@ -54,3 +54,3 @@
     const defaultValue = value.trim();
-    const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
+    const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\([^()]*\))?))*\)$/);
     const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
       do {
-        ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
+        ref = /var\( *([^),]*) *(?:, *([^(),]*(\([^()]*\))?))*\)/.exec(findRef);
         if (ref) {
EOF
@@ -54,3 +54,3 @@
const defaultValue = value.trim();
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)$/);
const res = defaultValue.match(/^var\( *([^),]*) *(?:, *([^(),]*(\([^()]*\))?))*\)$/);
const ret: CssVariable = { name, defaultValue };
@@ -65,3 +65,3 @@
do {
ref = /var\( *([^),]*) *(?:, *([^(),]*(\(.*\))?))*\)/.exec(findRef);
ref = /var\( *([^),]*) *(?:, *([^(),]*(\([^()]*\))?))*\)/.exec(findRef);
if (ref) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@matthieu-crouzet matthieu-crouzet linked an issue Nov 22, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Review and cleanup eslint-config
4 participants