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

Fix overrides.files negated pattern regression #7056

Closed
emmasax opened this issue Jul 7, 2023 · 3 comments · Fixed by #7468
Closed

Fix overrides.files negated pattern regression #7056

emmasax opened this issue Jul 7, 2023 · 3 comments · Fixed by #7468
Labels
status: wip is being worked on by someone type: bug a problem with a feature or rule

Comments

@emmasax
Copy link

emmasax commented Jul 7, 2023

What minimal example or steps are needed to reproduce the bug?

Create file fontSizeAllowedFile.tsx:

import { css } from '@emotion/react';

export const someStyling = css`
  font-size: 16px;
  color: white;
`;

What minimal configuration is needed to reproduce the bug?

Using glob pattern to exclude files (!(files)) does not work in Stylelint 15. It does work in previous versions.

Using the positive glob does include only this file ["*/**/fontSizeAllowedFile.tsx"], just negating it does not work.

{
  "customSyntax": "postcss-styled-syntax",
  "rules": {
    "property-disallowed-list": null
  },
  "overrides": [
    {
      "files": ["!(*/**/fontSizeAllowedFile.tsx)"],
      "rules": {
        "property-disallowed-list": ["font-size", "font-weight"]
      }
    }
  ]
}

How did you run Stylelint?

Via nx stylelint command

Which Stylelint-related dependencies are you using?

{
    "postcss-styled-syntax": "^0.4.0",
    "stylelint": "^15.10.1",
    "stylelint-config-standard": "^33.0.0"
}

What did you expect to happen?

File should not run disallowed list on the excluded file.

What actually happened?

File is not excluded

 4:3  ✖  Unexpected property "font-size"    property-disallowed-list

Do you have a proposal to fix the bug?

No response

@Mouvedia
Copy link
Contributor

Mouvedia commented Jul 7, 2023

I guess it's just a matter of doing a git bisect, if it used to work.
The only PR I found which looks related is #​6547.

@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule labels Jul 9, 2023
@jeddy3 jeddy3 changed the title Glob pattern for excluding files does not seem to work in Stylelint 15 Fix overrides.files negated pattern regression Jul 9, 2023
@jeddy3
Copy link
Member

jeddy3 commented Jul 9, 2023

@emmasax Thanks for the detailed report and for using the template.

I can reproduce this locally with:

{
  "rules": {
    "color-no-invalid-hex": null
  },
  "overrides": [
    {
      "files": ["!(*/**/test.css)"],
      "rules": {
        "color-no-invalid-hex": true
      }
    }
  ]
}
/* /test/test.css */
a {
  color: #00;
}

15.10.1:

jeddy3@mac stylelint-test % npx stylelint "**/*.css"

test/test.css
 2:10  ✖  Unexpected invalid hex color "#00"  color-no-invalid-hex

1 problem (1 error, 0 warnings)

14.16.1:

jeddy3@mac stylelint-test % npx stylelint "**/*.css"
(no warnings)

I've labelled the issue as ready to implement. Please consider contributing if you have time. It may require a bit of digging, though.

@ybiquitous
Copy link
Member

Sorry for the late response. As @Mouvedia guessed, I produced this bug through PR #6547. The bug is at:

// E.g. `*.css` matches any CSS files in any directories.
micromatch.isMatch(filePath, files, { dot: true, basename: true })
) {
config = mergeConfigs(config, configOverrides);
}

Here's a simple confirmation. Returning true by isMatch() for negation patterns (e.g. !(**/test.css)) adds an input file path (e.g. /foo/test.css) to lint targets.

micromatch = require('micromatch');
micromatch.isMatch('/foo/test.css', ['!(**/test.css)'], { dot: true, basename: true });
//=> true

I'll create a patch pull request soon.

However, this glob's syntax/behavior depends on a glob library (currently micromatch and is undocumented in the Stylelint document. So, I recommend using ignoreFiles instead for clarity and stability. E.g.

{
-	files: ['!(**/test.css)'],
+	files: ['**/*.css'],
+	ignoreFiles: ['**/test.css'],
}

@ybiquitous ybiquitous added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone type: bug a problem with a feature or rule
Development

Successfully merging a pull request may close this issue.

4 participants