Skip to content

Commit 746ab59

Browse files
authored
Upgrades to latest version of @ember-template-lint/todo-utils with fuzzy matching (#213)
* chore: Upgrades @ember-template-lint/todo-utils to latest version w/fuzzy matching
1 parent d648608 commit 746ab59

File tree

13 files changed

+1433
-814
lines changed

13 files changed

+1433
-814
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
},
5050
"rules": {
5151
"node/no-extraneous-import": "off",
52-
"node/no-unpublished-import": "off"
52+
"node/no-unpublished-import": "off",
53+
"@typescript-eslint/no-non-null-assertion": "off"
5354
}
5455
},
5556
{
56-
"files": ["src/types/index.ts"],
57+
"files": ["src/types/index.ts"],
5758
"rules": {
5859
"@typescript-eslint/no-namespace": "off"
5960
}

.github/workflows/ci-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
os: [ubuntu-latest, windows-latest]
19+
os: [ubuntu-latest]
2020
node: ['12']
2121

2222
steps:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
4+
function addOne(i) {
5+
6+
if (i != NaN) {
7+
8+
return i++;
9+
}
10+
11+
return;
12+
}

__tests__/__utils__/fake-project.ts

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { TodoConfig } from '@ember-template-lint/todo-utils';
2-
import { execSync } from 'child_process';
1+
import {
2+
DaysToDecay,
3+
DaysToDecayByRule,
4+
LintTodoPackageJson,
5+
TodoConfigByEngine,
6+
} from '@ember-template-lint/todo-utils';
7+
import { dirname, join } from 'path';
38
import fixturify from 'fixturify';
49
import Project from 'fixturify-project';
10+
import { mkdirpSync, symlinkSync } from 'fs-extra';
511

612
const DEFAULT_ESLINT_CONFIG = `{
713
"env": {
@@ -67,7 +73,7 @@ export class FakeProject extends Project {
6773
static getInstance(): FakeProject {
6874
const project = new this();
6975

70-
project.addDevDependency('eslint', '^7.10.0');
76+
// project.addDevDependency('eslint', '^7.10.0');
7177

7278
project.files['eslint-config.json'] = DEFAULT_ESLINT_CONFIG;
7379

@@ -82,30 +88,83 @@ export class FakeProject extends Project {
8288
description: 'Fake project',
8389
repository: 'http://fakerepo.com',
8490
});
91+
92+
// link binary
93+
this.symlink(
94+
join(__dirname, '../..', 'node_modules', '.bin', 'eslint'),
95+
join(this.baseDir, 'node_modules', '.bin', 'eslint')
96+
);
97+
98+
// link package
99+
this.symlink(
100+
join(__dirname, '../..', 'node_modules', 'eslint'),
101+
join(this.baseDir, 'node_modules', 'eslint')
102+
);
85103
}
86104

87105
write(dirJSON: fixturify.DirJSON): void {
88106
Object.assign(this.files, dirJSON);
89107
this.writeSync();
90108
}
91109

92-
writeTodoConfig(todoConfig: TodoConfig): void {
110+
setShorthandPackageJsonTodoConfig(daysToDecay: DaysToDecay): void {
93111
this.pkg = Object.assign({}, this.pkg, {
94112
lintTodo: {
95-
daysToDecay: todoConfig,
113+
daysToDecay,
96114
},
97115
});
98116

99117
this.writeSync();
100118
}
101119

102-
install(): void {
103-
const cmd = 'yarn install --silent';
120+
setPackageJsonTodoConfig(
121+
daysToDecay: DaysToDecay,
122+
daysToDecayByRule?: DaysToDecayByRule
123+
): void {
124+
const todoConfig: LintTodoPackageJson = {
125+
lintTodo: {
126+
eslint: {
127+
daysToDecay,
128+
},
129+
},
130+
};
131+
132+
if (daysToDecayByRule) {
133+
(<TodoConfigByEngine>todoConfig.lintTodo)!['eslint'].daysToDecayByRule =
134+
daysToDecayByRule;
135+
}
136+
137+
this.pkg = Object.assign({}, this.pkg, todoConfig);
138+
139+
this.writeSync();
140+
}
141+
142+
setLintTodorc(
143+
daysToDecay: DaysToDecay,
144+
daysToDecayByRule?: DaysToDecayByRule
145+
): void {
146+
const todoConfig: TodoConfigByEngine = {
147+
eslint: {
148+
daysToDecay,
149+
},
150+
};
104151

105-
try {
106-
execSync(cmd, { cwd: this.baseDir });
107-
} catch {
108-
throw new Error(`Couldn't install dependencies using ${cmd}`);
152+
if (daysToDecayByRule) {
153+
todoConfig['eslint'].daysToDecayByRule = daysToDecayByRule;
109154
}
155+
156+
this.write({
157+
'.lint-todorc.js': `module.exports = ${JSON.stringify(
158+
todoConfig,
159+
// eslint-disable-next-line unicorn/no-null
160+
null,
161+
2
162+
)}`,
163+
});
164+
}
165+
166+
symlink(source: string, target: string): void {
167+
mkdirpSync(dirname(target));
168+
symlinkSync(source, target);
110169
}
111170
}

__tests__/__utils__/get-fixture.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { join, resolve } from 'path';
22
import { ESLint } from 'eslint';
33
import { readFileSync, readJsonSync } from 'fs-extra';
4-
import { TemplateLintResult } from '@ember-template-lint/todo-utils';
54

65
const cache: Map<string, string> = new Map();
76

@@ -22,9 +21,10 @@ export function getStringFixture(fileName: string): string {
2221
return contents;
2322
}
2423

25-
export function getObjectFixture<
26-
T extends ESLint.LintResult | TemplateLintResult
27-
>(fileName: string, tmp: string): T[] {
24+
export function getObjectFixture<T extends ESLint.LintResult>(
25+
fileName: string,
26+
tmp: string
27+
): T[] {
2828
const fixture = readJsonSync(
2929
resolve(join('./__tests__/__fixtures__/', fileName))
3030
);

0 commit comments

Comments
 (0)