Fix lint plugins & tests on Windows

This commit is contained in:
Yury Bondarenko
2024-04-25 11:37:28 +02:00
parent 671e9f172b
commit 145a0a04b6
3 changed files with 22 additions and 15 deletions

View File

@@ -14,3 +14,15 @@ export function match(rangeA: number[], rangeB: number[]) {
export function stringLiteral(value: string): string {
return `'${value}'`;
}
/**
* Transform Windows-style paths into Unix-style paths
*/
export function toUnixStylePath(path: string): string {
// note: we're assuming that none of the directory/file names contain '\' or '/' characters.
// using these characters in paths is very bad practice in general, so this should be a safe assumption.
if (path.includes('\\')) {
return path.replace(/^[A-Z]:\\/, '/').replaceAll('\\', '/');
}
return path;
}

View File

@@ -16,8 +16,6 @@ import {
isPartOfViewChild,
} from './angular';
import {
AnyRuleContext,
getFilename,
isPartOfClassDeclaration,
isPartOfTypeExpression,
} from './typescript';
@@ -152,6 +150,7 @@ class ThemeableComponentRegistry {
const glob = require('glob');
// note: this outputs Unix-style paths on Windows
const wrappers: string[] = glob.GlobSync(prefix + 'src/app/**/themed-*.component.ts', { ignore: 'node_modules/**' }).found;
for (const wrapper of wrappers) {
@@ -245,17 +244,6 @@ export function inThemedComponentOverrideFile(filename: string): boolean {
return themeableComponents.byBasePath.has(`src/${match[1]}`);
}
export function inThemedComponentFile(context: AnyRuleContext): boolean {
themeableComponents.initialize();
const filename = getFilename(context);
return [
() => themeableComponents.byBasePath.has(filename),
() => themeableComponents.byWrapperPath.has(filename),
() => inThemedComponentOverrideFile(filename),
].some(predicate => predicate());
}
export function allThemeableComponents(): ThemeableComponentRegistryEntry[] {
themeableComponents.initialize();
return [...themeableComponents.entries];

View File

@@ -10,14 +10,21 @@ import {
TSESTree,
} from '@typescript-eslint/utils';
import { match } from './misc';
import {
match,
toUnixStylePath,
} from './misc';
export type AnyRuleContext = TSESLint.RuleContext<string, unknown[]>;
/**
* Return the current filename based on the ESLint rule context as a Unix-style path.
* This is easier for regex and comparisons to glob paths.
*/
export function getFilename(context: AnyRuleContext): string {
// TSESLint claims this is deprecated, but the suggested alternative is undefined (could be a version mismatch between ESLint and TSESlint?)
// eslint-disable-next-line deprecation/deprecation
return context.getFilename();
return toUnixStylePath(context.getFilename());
}
export function getSourceCode(context: AnyRuleContext): TSESLint.SourceCode {