-
Notifications
You must be signed in to change notification settings - Fork 235
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
check for svg to extend the supportedExtensions #2366
base: master
Are you sure you want to change the base?
check for svg to extend the supportedExtensions #2366
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some useful context in these PRs / linked issues about our current behavior:
- Allow linting individual files with arbitrary extensions. #1556
- Add
.html
to supported file extensions #1232
I haven't had a chance to review all of this yet so I don't have a recommendation yet.
I do want to call out ESLint's behavior, as long-term, we've been moving toward ember-template-lint matching ESLint's behavior.
https://eslint.org/docs/user-guide/command-line-interface#--ext
--ext
This option allows you to specify which file extensions ESLint will use when searching for target files in the directories you specify. By default, ESLint lints *.js files and the files that match the overrides entries of your configuration.
Note: --ext is only used when the arguments are directories. If you use glob patterns or file names, then --ext is ignored.
For example, npx eslint lib/* --ext .js will match all files within the lib/ directory, regardless of extension.
@@ -221,6 +221,10 @@ export function getPossibleOptionNames(specifiedOptions) { | |||
function executeGlobby(workingDir, pattern, ignore) { | |||
let supportedExtensions = new Set(['.hbs', '.handlebars']); | |||
|
|||
if (path.extname(pattern) === '.svg') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't think that treating a regexp pattern as a path is robust enough. A regexp pattern doesn't necessarily look like a path, so while this might work sometime, it isn't really a reliable way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks for that info, how would you feel about something like:
if (pattern.endsWith('.svg')) {
supportedExtensions.add('.svg')
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't help unfortunately. As soon as someone has a pattern like templates/*.{hbs,svg}
, it fails.
Following ESLint's behaviour would be problematic in this case, since we would prefer to be able to use a glob pattern. |
@SkoebaSteve I think ESLint's behavior would actually work for you: I tested with ESLint and any file matching a glob passed to ESLint will be linted, not limited to predefined file extensions. Since we have been trying to align ember-template-lint with ESLint's behavior, we could move toward this, but it wouldn't be for a while given that we just had a major release. |
@bmish that sounds great, thanks for checking!
Ok I understand, maybe the best thing for us now is to wait for this then. Pretty new to ember-template-lint but I'm willing to help out, is there anything you can think of? |
Just a heads up that we're going to release the v5 version in the next week or two (#2319). It would be a good time to make any breaking changes. |
We have relied for over a year on ember template lint to lint our svg files for certain issues(embedded images, text, etc). This is useful, since we can rely on the integration we already use for our template file lint.
We used to have our files only nested one deep, so no need for doing a glob search pattern. We reorganized our folder structure and will now have svgs nested in multiple folders deep.
When wrapping our lint command in
\"public/**/*.svg\"
, it does seem to do a recursive glob search, but in this case it executes the executeGlobby function and that hardcodes the supported extensions to belet supportedExtensions = new Set(['.hbs', '.handlebars']);
This change proposes to allow for linting of SVG files as well. I'm open to ideas and suggestions, one idea I had is to extend it with
.html
files as well for example.ps. I was looking into adding a test scenario but I'm not sure where to best place this so any suggestion would be great!