-
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
Changes from 1 commit
035923e
514ae2f
1859807
2dd183c
827faef
10a09db
e2804b1
5e964ca
372197b
95e33c8
8b30ec5
e44d324
45158a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
type FindUp = (name: string, opts: { cwd: string; type: string }) => Promise<string | undefined>; | ||
type LinterVerifyArgs = { source: string; moduleId: string; filePath: string }; | ||
|
@@ -88,7 +89,7 @@ export default class TemplateLinter { | |
return this.server.projectRoots.projectForUri(textDocument.uri); | ||
} | ||
|
||
private sourcesForDocument(textDocument: TextDocument, templateLintVersion: string): string[] { | ||
private sourcesForDocument(textDocument: TextDocument, templateLintVersion: SemVer | null): string[] { | ||
const ext = getExtension(textDocument); | ||
|
||
if (ext !== null && !extensionsToLint.includes(ext)) { | ||
|
@@ -98,8 +99,11 @@ export default class TemplateLinter { | |
const documentContent = textDocument.getText(); | ||
|
||
// we assume that ember-template-lint v5 could handle js/ts/gts/gjs files | ||
if (!templateLintVersion) { | ||
return [documentContent]; | ||
} | ||
|
||
if (templateLintVersion >= '5') { | ||
if (semver.gte(templateLintVersion, '5.0.0')) { | ||
return [documentContent]; | ||
} | ||
Comment on lines
+107
to
109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work sadly. semver.gte(semver.minVersion(templateLintVersion)?.version ?? '0.0.0', '5.0.0') |
||
|
||
|
@@ -152,11 +156,12 @@ export default class TemplateLinter { | |
} | ||
|
||
const linterMeta = project.dependenciesMeta.find((dep) => dep.name === 'ember-template-lint'); | ||
const linterVersion = linterMeta?.version.split('.')[0] || 'unknown'; | ||
|
||
let sources = []; | ||
|
||
try { | ||
const linterVersion = linterMeta?.version ? semver.parse(linterMeta.version) : null; | ||
lifeart marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems linterMeta.version may be already "broken" by semver.clean 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. We just need to fix that ts error There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lifeart this approach does work, you just need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other approach is just use the method to get the |
||
|
||
sources = this.sourcesForDocument(textDocument, linterVersion); | ||
} catch (e) { | ||
return; | ||
|
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 asversionString[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. :\