Dan503 / gulp-auto-imports

Auto generate import-only files for any file type. SCSS, JS, TS, Pug, whatever you want.
MIT License
1 stars 0 forks source link

Clean Import Paths #10

Closed Esteban-Rocha closed 3 years ago

Esteban-Rocha commented 5 years ago

Hi, Thanks for the plugin! it's awesome :clap: I'm implementing it and I use sass-lint and one the rules I like to have is Clean Import Paths, I wasn't able to configure this so it prints only the name of the file without extension and leading underscore for partials.

So unless I'm failing real hard here I was wondering if you could implement this in the future? It sure will be nice to be able to customize the "format" setting for teams/personal preferences on code formatting.

Dan503 commented 5 years ago

Glad you like the plugin 😊

This is actually my first public submitted issue on any of my creations.

Anyway, yeah what you are asking for isn't supported at the moment.

I might add support for this in the future but it would be a pretty low priority.

Are you able to output the file into a folder that is not being tracked by sass-lint? Or can you tell sass-lint to ignore the output file?

Esteban-Rocha commented 5 years ago

Yeah sure! It's more of a cosmetic change I agree, any ways I can ignore it for the time being, but it surely will come in handy when implementing it on company or client projects where a code formatting and linting is enforced.

And yeah, quite handy plugin, it's proven to be a time saver already :zap:

Dan503 commented 5 years ago

I think if I did implement this I would make it a slightly different syntax on the $path placeholder.

By default $path would output path/to/file.ext and $.path would output ./path/to/file.ext. This would mean a breaking change though.

It would also make issues #6 and #7 more difficult to implement because then I would need to do this:

$\_path = single back slashes $.\_path = single back slashes with .\ at the start $\\path = escaped back slashes $.\\path = escaped back slashes with .\\ at the start

$absolute = absolute path $.absolute = absolute path with ./ at start $\_absolute = absolute path with single back slashes $.\_absolute = absolute path with single back slashes and .\ at start $\\absolute = escaped back slashes $.\\absolute = escaped back slashes with .\\ at the start

The main reason I am reluctant to support this though is that it makes the regex for detecting the existing paths more difficult to write and less reliable. I intentionally put the ./ at the start because it was a clear indicator that it was the start of a path name so the order retention regex had an easy hook to grab onto.

Esteban-Rocha commented 5 years ago

Thanks for the detailed info Daniel, I understand now that this is more complicated that it may seem, I may propose an external solution in that case, to post-process the file-loader.scss in case anyone else may have the same issue.

I may fork this and study the code, if I can think of a better and clean idea I'll let you know! Thanks!

Dan503 commented 5 years ago

The issue with post-processing the file is that it will break the order retention functionality. I could fairly easily add a setting that removes the ./ at the front of all file paths. The difficulty is the order retention regex.

The regex is expecting ./ at the front so if it is removed, it will not find any matches. It will then throw out whatever your existing import order is and output the default order.

Dan503 commented 5 years ago

Also it's not just the starting ./ which marks the start of a file path but also the ending .ext is a clear indicator for the end of a path string.

I have no idea what the user has written before and after a path string so I can only rely on what the plugin is definitely outputting.

Dan503 commented 4 years ago

Hi, I'm revisiting this.

I realized that in order to support TypeScript I have to have a way to output clean import paths. So I am adding support for a new $noExtPath placeholder to formater strings and I'm going to provide a warning if problematic settings like retainOrder are enabled.

Most of the time retainOrder isn't needed so I think this is a reasonable option.

I'm also providing new formatReplace and templateReplace functions in the next version that can do more advanced clean up stuff.

Esteban-Rocha commented 4 years ago

Awesome, thanks for the heads-up @Dan503, this will be awesome now than ever as I'm also using TypeScript as many others so it will definitively increase the usefulness of this plugin. 👏

Dan503 commented 3 years ago

Typescript support added in v3.2.0 🎉

Sorry about the long delay on this. I got caught up with other stuff.

Dan503 commented 3 years ago

@Esteban-Rocha check out the new features in v3.2.0 🥳

https://github.com/Dan503/gulp-auto-imports/releases/tag/v3.2.0