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

Use broader template-lint range #418

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

Conversation

NullVoxPopuli
Copy link
Member

@NullVoxPopuli NullVoxPopuli commented Nov 22, 2024

Closes #417

@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review November 22, 2024 15:18
Comment on lines 102 to 104
if (templateLintVersion === '5') {
if (templateLintVersion >= '5') {
return [documentContent];
}

Choose a reason for hiding this comment

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

@NullVoxPopuli this isn't enough I don't believe, the templateLintVersion might come in as a ^ or a ~

Copy link
Member Author

Choose a reason for hiding this comment

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

excellent point -- I'll update this to use semver

Copy link
Contributor

Choose a reason for hiding this comment

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

@NullVoxPopuli we need parseInt here :)

Copy link
Member Author

Choose a reason for hiding this comment

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

not if it's a ^ -- gonna use the semver package. sorry for the low effort initial PR!

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@lifeart lifeart left a comment

Choose a reason for hiding this comment

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

seems we need to convert string to int

Comment on lines 102 to 104
if (templateLintVersion === '5') {
if (templateLintVersion >= '5') {
return [documentContent];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@NullVoxPopuli we need parseInt here :)

@@ -12,6 +12,7 @@ import Server from './server';
import { Project } from './project';
import { getRequireSupport } from './utils/layout-helpers';
import { getFileRanges, RangeWalker } from './utils/glimmer-script';
import semver, { SemVer } from 'semver';
Copy link
Contributor

Choose a reason for hiding this comment

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

nope, it's extra bundle size

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, my bad, we already have it in layout helpers, we good in this case.

Copy link
Contributor

@lifeart lifeart Nov 22, 2024

Choose a reason for hiding this comment

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

but it seems we don't need it anyway for our case

Copy link

@arthur5005 arthur5005 Nov 22, 2024

Choose a reason for hiding this comment

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

@lifeart why not? The raw string ^5.13.0 for example can't be read as versionString[0] otherwise you get a version ^ no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

@arthur5005 arthur5005 Nov 22, 2024

Choose a reason for hiding this comment

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

@lifeart just tested how clean works, I think it doesn't work how we think it's supposed to work, unless I'm missing something.

I might not know how the package strings pre-processed though before reaching the clean method.
Screenshot 2024-11-22 at 8 50 24 AM

Copy link
Contributor

Choose a reason for hiding this comment

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

@arthur5005 oh my, thank you for pointing to it!

Choose a reason for hiding this comment

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

^- @NullVoxPopuli To @lifeart's point, I think how we parse dependency versions is the real problem here, I'm imagining the version on the dep meta is null for all unpinned projects. :\

src/template-linter.ts Outdated Show resolved Hide resolved
*
* (same as when errors are thrown from sourcesForDocument)
*/
const linterVersion = linterMeta?.version ? semver.parse(linterMeta.version) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems linterMeta.version may be already "broken" by semver.clean
#418 (comment)

Seems we need to add some tests to ensure how it's actually works for real-life cases.

Choose a reason for hiding this comment

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

Best to just set the version directly, and expect all users to have to use semver to interact with the value. Unless there's a unified way to get the locked / installed version.

Copy link
Contributor

Choose a reason for hiding this comment

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

@arthur5005 another option I see here - is to get actual version from installed ember-template-lint package. In this case we could get just exact value, without prefixes and postfixes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

@arthur5005 arthur5005 Nov 22, 2024

Choose a reason for hiding this comment

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

@lifeart yeah, if there's a reliable way to get exact versions across all package managers, let's do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

how so? I was just gonna fix the getDepIfExists code

Choose a reason for hiding this comment

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

I think that's fine too. I think @lifeart would prefer getting exact versions, but we could probably live with major version only checking for now.

Choose a reason for hiding this comment

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

We just need to fix that ts error All imports in import declaration are unused. and I think this is ready @NullVoxPopuli

*
* (same as when errors are thrown from sourcesForDocument)
*/
const linterVersion = linterMeta?.version ? semver.parse(linterMeta.version) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

this approach not going to work for us:
image

I agree with @arthur5005 - we need to implement proper version resolution from Project.dependencyMap

Choose a reason for hiding this comment

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

@lifeart this approach does work, you just need to use minVersion, not parse
Screenshot 2024-11-25 at 11 23 20 AM

Choose a reason for hiding this comment

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

The other approach is just use the method to get the SemVer object directly, and put that in the meta instead of the string.

@@ -151,12 +156,24 @@ export default class TemplateLinter {
return;
}

const linterMeta = project.dependenciesMeta.find((dep) => dep.name === 'ember-template-lint');
const linterVersion = linterMeta?.version.split('.')[0] || 'unknown';
const linterMeta = project.dependencyMap.get('ember-template-lint');
Copy link
Contributor

Choose a reason for hiding this comment

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

likely we need to add integration test for it, or test locally :)

Comment on lines +107 to 109
if (semver.gte(templateLintVersion, '5.0.0')) {
return [documentContent];
}
Copy link

@arthur5005 arthur5005 Nov 25, 2024

Choose a reason for hiding this comment

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

This doesn't work sadly.
Something like the following is technically correct:

semver.gte(semver.minVersion(templateLintVersion)?.version ?? '0.0.0', '5.0.0')

* (same as when errors are thrown from sourcesForDocument)
*/
const version = linterMeta?.package.version;
const linterVersion = version ? semver.parse(version) : null;

Choose a reason for hiding this comment

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

semver.minVersion(version)?.version ?? '0.0.0'

Copy link
Contributor

Choose a reason for hiding this comment

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

I updated logic on how we resolve template-lint version, now it should be taken from deps, need to test it...

@NullVoxPopuli
Copy link
Member Author

it works
image

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.

Template lint don't work properly
3 participants