Skip to content

Commit

Permalink
Fix lint plugins & tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ybnd committed Apr 25, 2024
1 parent 671e9f1 commit 145a0a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
12 changes: 12 additions & 0 deletions lint/src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 1 addition & 13 deletions lint/src/util/theme-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
isPartOfViewChild,
} from './angular';
import {
AnyRuleContext,
getFilename,
isPartOfClassDeclaration,
isPartOfTypeExpression,
} from './typescript';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
Expand Down
11 changes: 9 additions & 2 deletions lint/src/util/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 145a0a0

Please sign in to comment.