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

[feature] Add globs (**/*) feature to excludes #16

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Ranger-X
Copy link

@Ranger-X Ranger-X commented Nov 21, 2024

For now this work only for license / copyright-excludes and nocyrillic / no-cyrillic-file-excludes section

@Ranger-X Ranger-X self-assigned this Nov 21, 2024
@Ranger-X Ranger-X changed the title Add globs (**/*) feature to excludes [feature] Add globs (**/*) feature to excludes Nov 21, 2024
@Ranger-X Ranger-X marked this pull request as draft November 22, 2024 05:39
@Ranger-X Ranger-X marked this pull request as ready for review November 22, 2024 07:22
@juev juev requested review from juev and yalosev November 22, 2024 07:36
internal/fsutils/fsutils.go Outdated Show resolved Hide resolved
internal/fsutils/fsutils.go Outdated Show resolved Hide resolved
internal/fsutils/fsutils.go Show resolved Hide resolved
internal/fsutils/fsutils.go Outdated Show resolved Hide resolved
internal/fsutils/fsutils.go Outdated Show resolved Hide resolved
internal/fsutils/fsutils_test.go Outdated Show resolved Hide resolved
internal/fsutils/fsutils_test.go Show resolved Hide resolved
pkg/linters/license/license.go Outdated Show resolved Hide resolved
pkg/linters/no-cyrillic/no-cyrillic.go Outdated Show resolved Hide resolved
name: "plain string with mask",
args: args{
str: "test-string.delimited.by.dots",
pattern: "*.by.dots",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, then the pattern will fit any module without restrictions?
Do we want to add regexp only for parsing the file path? Or for the whole line?
If only for the path, then it is reasonable, if for the string, then in my opinion, it will introduce unnecessary errors and unprovable behavior.


func toRegexp(pattern string) string {
// code from https://github.com/guillermo/doubleglob/blob/main/double_glob.go
replaces := regexp.MustCompile(`(\.)|(\*\*/)|(\*)|([^/\*.]+)|(/)`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing, why do we use groups here? As far as I can see, we just match whether this regexp fits our string or not.

for _, fileName := range files {
name, _ := strings.CutPrefix(fileName, m.GetPath())
name = m.GetName() + ":" + name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we create a name including the module name so that it can be compared with the list of exceptions. The proposed change below does not do this. As a result, we will compare files with exceptions from other modules.

@@ -66,7 +66,7 @@ func (o *NoCyrillic) Run(m *module.Module) (errors.LintRuleErrorsList, error) {
for _, fileName := range files {
name, _ := strings.CutPrefix(fileName, m.GetPath())
name = m.GetName() + ":" + name
if slices.Contains(o.cfg.NoCyrillicFileExcludes, name) {
if fsutils.StringMatchAnyMask(name, o.cfg.NoCyrillicFileExcludes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name will look like this: upmeter:/hooks/.venv/dir/file.py

We compare it with an exception like upmeter:/hooks/. venv/**/*

It looks like it should work. It would not be bad to make a test for this solution.

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

Successfully merging this pull request may close these issues.

2 participants