snowcoders / sortier

An opinionated code sorter
https://snowcoders.github.io/sortier/
MIT License
30 stars 2 forks source link

Unable to exclude files using glob pattern #1763

Open mohammadalipak opened 2 years ago

mohammadalipak commented 2 years ago

Language

Typescript | JavaScript | CSS

Sample input source code

// sample file structure
src/
├── app/
│   ├── app.css
│   ├── app.html
│   └── app.js
└── package.json

// sortier command
sortier '**/!(*.json|*.css)'

Expected output

// result
sortier should have only modified the html and js files

Actual output (or error message)

// result
sortier modifies ALL files and does not exclude the css and json files
k2snowman69 commented 2 years ago

Thanks for the heads up, I've got a working reproduction locally. Trying to figure out the fix.

k2snowman69 commented 2 years ago

From what I can tell this issue is likely in globby or somewhere lower but I can't tell why. Let me explain, sortier uses globby to perform all glob interpretations and when I debug the code I see the following:

// args =  ['**/!(*.json|*.css)']
 const files = globbySync(args);
// files = ['package.json', 'app/app.css', 'app/app.html', 'app/app.js']

Testing the glob in

Seems to return the correct list of files so I'm not sure why this is happening.

Also, it seems **/*.{json,css} and **/*.(json|css) works perfectly fine

k2snowman69 commented 2 years ago

I created https://github.com/k2snowman69/issue-sortier-1763/blob/main/app/globby.test.js just to express the issue with globby a bit better. This reproduces the environment described in this bug. I created a test that shows that

Not going to lie, I'm confused. This might be something to follow up on the globby library with.

A work around might be temporarily using the .sortierignore file instead but i haven't tested this yet