-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: master
Are you sure you want to change the base?
Conversation
src/template-linter.ts
Outdated
if (templateLintVersion === '5') { | ||
if (templateLintVersion >= '5') { | ||
return [documentContent]; | ||
} |
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.
@NullVoxPopuli this isn't enough I don't believe, the templateLintVersion might come in as a ^
or a ~
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.
excellent point -- I'll update this to use semver
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.
@NullVoxPopuli we need parseInt
here :)
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.
not if it's a ^
-- gonna use the semver package. sorry for the low effort initial PR!
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.
@NullVoxPopuli it's not a case - we have this precondition - https://github.com/ember-tooling/ember-language-server/blob/master/src/utils/layout-helpers.ts#L293
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.
seems we need to convert string to int
src/template-linter.ts
Outdated
if (templateLintVersion === '5') { | ||
if (templateLintVersion >= '5') { | ||
return [documentContent]; | ||
} |
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.
@NullVoxPopuli we need parseInt
here :)
src/template-linter.ts
Outdated
@@ -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'; |
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.
nope, it's extra bundle size
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.
Ah, my bad, we already have it in layout helpers, we good in this case.
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.
but it seems we don't need it anyway for our case
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.
@lifeart why not? The raw string ^5.13.0
for example can't be read as versionString[0]
otherwise you get a version ^
no?
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.
@arthur5005 it's not a case, we already cleaning value here: https://github.com/ember-tooling/ember-language-server/blob/master/src/utils/layout-helpers.ts#L293
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.
@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.
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.
@arthur5005 oh my, thank you for pointing to it!
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.
^- @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
* | ||
* (same as when errors are thrown from sourcesForDocument) | ||
*/ | ||
const linterVersion = linterMeta?.version ? semver.parse(linterMeta.version) : null; |
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.
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.
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.
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.
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.
@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.
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.
cc @NullVoxPopuli seems code landed in https://github.com/ember-tooling/ember-language-server/pull/411/files#diff-6162d8c9873071bf9f26293887dc9669d8c375d34f5e3457fc57e2cbc17cbb60R41 may help here..
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.
@lifeart yeah, if there's a reliable way to get exact versions across all package managers, let's do that.
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.
how so? I was just gonna fix the getDepIfExists code
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.
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.
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.
We just need to fix that ts error All imports in import declaration are unused.
and I think this is ready @NullVoxPopuli
src/template-linter.ts
Outdated
* | ||
* (same as when errors are thrown from sourcesForDocument) | ||
*/ | ||
const linterVersion = linterMeta?.version ? semver.parse(linterMeta.version) : null; |
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 approach not going to work for us:
I agree with @arthur5005 - we need to implement proper version resolution from Project.dependencyMap
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.
@lifeart this approach does work, you just need to use minVersion
, not parse
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.
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'); |
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.
likely we need to add integration test for it, or test locally :)
if (semver.gte(templateLintVersion, '5.0.0')) { | ||
return [documentContent]; | ||
} |
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 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; |
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.
semver.minVersion(version)?.version ?? '0.0.0'
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.
I updated logic on how we resolve template-lint version, now it should be taken from deps, need to test it...
Closes #417