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

feat: workingDir for ember-template-lint #397

Draft
wants to merge 1 commit into
base: component-context-info-origin
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/template-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { getFileRanges, RangeWalker } from './utils/glimmer-script';
type FindUp = (name: string, opts: { cwd: string; type: string }) => Promise<string | undefined>;
type LinterVerifyArgs = { source: string; moduleId: string; filePath: string };
class Linter {
constructor() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(_config?: { workingDir?: string }) {
return this;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -153,6 +154,7 @@ export default class TemplateLinter {

const linterMeta = project.dependenciesMeta.find((dep) => dep.name === 'ember-template-lint');
const linterVersion = linterMeta?.version.split('.')[0] || 'unknown';
const literSupportWorkingDir = linterVersion === '5' || linterVersion === '4';

let sources = [];

Expand All @@ -175,11 +177,19 @@ export default class TemplateLinter {
let linter: Linter;

try {
setCwd(project.root);
linter = new TemplateLinterKlass();
if (!literSupportWorkingDir) {
setCwd(project.root);
linter = new TemplateLinterKlass();
} else {
linter = new TemplateLinterKlass({
workingDir: project.root,
});
}
} catch (e) {
try {
setCwd(cwd);
if (!literSupportWorkingDir) {
setCwd(cwd);
}
} catch (e) {
logDebugInfo(e.stack);
}
Expand Down Expand Up @@ -212,7 +222,9 @@ export default class TemplateLinter {
}

try {
setCwd(cwd);
if (!literSupportWorkingDir) {
setCwd(cwd);
}
} catch (e) {
logDebugInfo(e.stack);
}
Expand Down