Skip to content

Commit 145a0a0

Browse files
committed
Fix lint plugins & tests on Windows
1 parent 671e9f1 commit 145a0a0

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

lint/src/util/misc.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ export function match(rangeA: number[], rangeB: number[]) {
1414
export function stringLiteral(value: string): string {
1515
return `'${value}'`;
1616
}
17+
18+
/**
19+
* Transform Windows-style paths into Unix-style paths
20+
*/
21+
export function toUnixStylePath(path: string): string {
22+
// note: we're assuming that none of the directory/file names contain '\' or '/' characters.
23+
// using these characters in paths is very bad practice in general, so this should be a safe assumption.
24+
if (path.includes('\\')) {
25+
return path.replace(/^[A-Z]:\\/, '/').replaceAll('\\', '/');
26+
}
27+
return path;
28+
}

lint/src/util/theme-support.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import {
1616
isPartOfViewChild,
1717
} from './angular';
1818
import {
19-
AnyRuleContext,
20-
getFilename,
2119
isPartOfClassDeclaration,
2220
isPartOfTypeExpression,
2321
} from './typescript';
@@ -152,6 +150,7 @@ class ThemeableComponentRegistry {
152150

153151
const glob = require('glob');
154152

153+
// note: this outputs Unix-style paths on Windows
155154
const wrappers: string[] = glob.GlobSync(prefix + 'src/app/**/themed-*.component.ts', { ignore: 'node_modules/**' }).found;
156155

157156
for (const wrapper of wrappers) {
@@ -245,17 +244,6 @@ export function inThemedComponentOverrideFile(filename: string): boolean {
245244
return themeableComponents.byBasePath.has(`src/${match[1]}`);
246245
}
247246

248-
export function inThemedComponentFile(context: AnyRuleContext): boolean {
249-
themeableComponents.initialize();
250-
const filename = getFilename(context);
251-
252-
return [
253-
() => themeableComponents.byBasePath.has(filename),
254-
() => themeableComponents.byWrapperPath.has(filename),
255-
() => inThemedComponentOverrideFile(filename),
256-
].some(predicate => predicate());
257-
}
258-
259247
export function allThemeableComponents(): ThemeableComponentRegistryEntry[] {
260248
themeableComponents.initialize();
261249
return [...themeableComponents.entries];

lint/src/util/typescript.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ import {
1010
TSESTree,
1111
} from '@typescript-eslint/utils';
1212

13-
import { match } from './misc';
13+
import {
14+
match,
15+
toUnixStylePath,
16+
} from './misc';
1417

1518
export type AnyRuleContext = TSESLint.RuleContext<string, unknown[]>;
1619

20+
/**
21+
* Return the current filename based on the ESLint rule context as a Unix-style path.
22+
* This is easier for regex and comparisons to glob paths.
23+
*/
1724
export function getFilename(context: AnyRuleContext): string {
1825
// TSESLint claims this is deprecated, but the suggested alternative is undefined (could be a version mismatch between ESLint and TSESlint?)
1926
// eslint-disable-next-line deprecation/deprecation
20-
return context.getFilename();
27+
return toUnixStylePath(context.getFilename());
2128
}
2229

2330
export function getSourceCode(context: AnyRuleContext): TSESLint.SourceCode {

0 commit comments

Comments
 (0)