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

check for svg to extend the supportedExtensions #2366

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SkoebaSteve
Copy link

@SkoebaSteve SkoebaSteve commented Feb 7, 2022

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 be let 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!

Copy link
Member

@bmish bmish left a 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:

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') {
Copy link
Member

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.

Copy link
Author

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')
}

Copy link
Member

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.

@SkoebaSteve
Copy link
Author

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.

Following ESLint's behaviour would be problematic in this case, since we would prefer to be able to use a glob pattern.

@bmish
Copy link
Member

bmish commented Feb 10, 2022

@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 bmish mentioned this pull request Feb 10, 2022
@SkoebaSteve
Copy link
Author

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.

@bmish that sounds great, thanks for checking!

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.

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?

@bmish bmish added the breaking label Feb 11, 2022
@bmish bmish added this to the 5.0.0 milestone Jun 15, 2022
@bmish
Copy link
Member

bmish commented Nov 4, 2022

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.

@bmish bmish mentioned this pull request Nov 19, 2022
@bmish bmish removed this from the 5.0.0 milestone Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants