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: the exclusion pattern **/* does not work as expected #265

Open
pil0u opened this issue Aug 1, 2022 · 3 comments
Open

Bug: the exclusion pattern **/* does not work as expected #265

pil0u opened this issue Aug 1, 2022 · 3 comments
Labels

Comments

@pil0u
Copy link

pil0u commented Aug 1, 2022

I have a project structure that looks like:

app
 |_ components
     |_ folder
         |_ some_file.html.erb
     |_ some_other_file.html.erb

I want to prevent a linter from analysing any file in the app/components folder. What I would do is:

HardCodedString:
  exclude:
    - '**/app/components/**/*'

The app/components/folder/some_file.html.erb is properly excluded, but the app/components/some_other_file.html.erb is not.

Is this expected?

@rafaelfranca
Copy link
Member

This seems like a bug to me. How Rubocop works for those files?

@pil0u
Copy link
Author

pil0u commented Oct 21, 2022

@rafaelfranca As an example, I have a rule in RuboCop that looks like

Lint/MissingSuper:
  Exclude:
    - "**/app/components/**/*"

and all my files in the app/components folder, nested in sub-folders or not, are properly excluded.

I would expect the same behaviour to work with erb-lint:

HardCodedString:
  exclude:
    - '**/app/components/**/*'

but my "non-nested" files are not properly excluded with that setup.
My current workaround is:

HardCodedString:
  exclude:
    - '**/app/components/**/*'
    - '**/app/components/*'

which is very cheap, but feels a little off.

@xiaohui-zhangxh
Copy link

This bug relates

File.fnmatch?(expanded_path, filename)

Per File.fnmatch documentation : https://apidock.com/ruby/v2_6_3/File/fnmatch%3F/class

pattern = '**/app/components/**/*'
File.fnmatch(pattern, '/a/app/components/foo') #=> false
File.fnmatch(pattern, '/a/app/components/foo/bar') #=> true

File.fnmatch(pattern, '/a/app/components/foo', File::FNM_PATHNAME) #=> true
File.fnmatch(pattern, '/a/app/components/foo/bar', File::FNM_PATHNAME) #=> true

So, if we don't change the code, the correct exclude pattern should be:

exclude:
- '*/app/components/*'
pattern = '*/app/components/*'
File.fnmatch(pattern, '/a/app/components/foo') #=> false
File.fnmatch(pattern, '/a/app/components/foo/bar') #=> true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants