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

[Bug?] Inconsistent matching patterns for files & folders #25

Closed
wenfangdu opened this issue Jun 4, 2023 · 10 comments
Closed

[Bug?] Inconsistent matching patterns for files & folders #25

wenfangdu opened this issue Jun 4, 2023 · 10 comments

Comments

@wenfangdu
Copy link

First of all, thank you for creating this.

Here are my current rules:

{
  "check-file/folder-naming-convention": [
    "error",
    {
      "*": "KEBAB_CASE"
    }
  ],
  "check-file/filename-naming-convention": [
    "error",
    {
      "*": "KEBAB_CASE"
    }
  ]
}

As you can see, the file name foB didn't throw the error:
image
But if I change the rules to:

{
  "check-file/folder-naming-convention": [
    "error",
    {
      "*": "KEBAB_CASE"
    }
  ],
  "check-file/filename-naming-convention": [
    "error",
    {
      "**": "KEBAB_CASE"
    }
  ]
}

Now it works as expected:
image
Notice the file pattern uses ** whereas the folder pattern uses *, is this inconsistency intentional or a bug?

@dukeluo
Copy link
Owner

dukeluo commented Jun 4, 2023

@wenfangdu Thanks for your issue, I think it isn't a bug, it is an interesting scenario.

When check-file plugin linting your file types/foo/sdoiOJI/foB.js:

  • * matches within a single directory level, while ** matches across multiple directory levels, including subdirectories.
  • the rule filename-naming-convention will use the target glob to match its path, so ** can select this file and get a lint error, while * cant select this file.
  • the rule folder-naming-convention will create it's all subdirectories firstly. In this case, this value will be ['types/', 'types/foo/', 'types/foo/sdoiOJI/', 'foo/', 'foo/sdoiOJI/', 'sdoiOJI/']. And then use the target glob to match the subdirectory item, so * can select the sdoiOJI/ item in your case, and get a lint error.

Hope my explanation helps you understand this scenario.

@wenfangdu
Copy link
Author

@dukeluo Thanks for the detailed explanation, that's a bit of mental overhead. If we unify this behavior/implementation i.e. use * to lint all files (same behavior as eslint overrides), could it be better?

@dukeluo
Copy link
Owner

dukeluo commented Jun 4, 2023

@dukeluo Thanks for the detailed explanation, that's a bit of mental overhead. If we unify this behavior/implementation i.e. use * to lint all files (same behavior as eslint overrides), could it be better?

Which behavior/implementation are you referring to? Do you mean "* matches within a single directory level, while ** matches across multiple directory levels"?

@wenfangdu
Copy link
Author

@dukeluo * matches across directory levels for both files and folders.

@wenfangdu
Copy link
Author

@dukeluo Or ** matches across directory levels for both files and folders, the point here is being consistent.

@dukeluo
Copy link
Owner

dukeluo commented Jun 4, 2023

@wenfangdu The behavior of the globstar** and the wildcard * come from the community. You can use this link to get more info. I think eslint overrides can use the wildcard * to select all the files across directories because its business logic ignores its folder, only care about its filename.

But this plugin cant do like this. For example, in your case (types/foo/sdoiOJI/foB.js), types/*/ will only select foo folder while types/**/ will select all its directories. Users can set the target scope according to their needs.

@wenfangdu
Copy link
Author

@dukeluo I understand, but the folder matching mechanism is not the same as the file one, e.g. if I set * for "check-file/folder-naming-convention", all folders & their subfolders will be matched, not just the root level folder names, therefore, inconsistent.

@dukeluo
Copy link
Owner

dukeluo commented Jun 4, 2023

@dukeluo I understand, but the folder matching mechanism is not the same as the file one, e.g. if I set * for "check-file/folder-naming-convention", all folders & their subfolders will be matched, not just the root level folder names, therefore, inconsistent.

I got your point. I will consider how to deal with this case.

dukeluo added a commit that referenced this issue Jun 7, 2023
@dukeluo
Copy link
Owner

dukeluo commented Jun 12, 2023

@wenfangdu The new version 2.4.0 is released, you can try it now.

@dukeluo dukeluo closed this as completed Jun 12, 2023
@wenfangdu
Copy link
Author

@dukeluo Sweet, thanks.

milos-sikic-nimbus-tech pushed a commit to milos-sikic-nimbus-tech/eslint-plugin-check-file that referenced this issue Jul 5, 2023
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

No branches or pull requests

2 participants