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 22531aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 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

Check failure on line 22 in lint/src/util/misc.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Trailing spaces not allowed

Check failure on line 22 in lint/src/util/misc.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Trailing spaces not allowed
if (path.includes('\\')) {
return path.replace(/^[A-Z]:\\/, '/')
.replaceAll('\\', '/');

Check failure on line 25 in lint/src/util/misc.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Expected indentation of 6 spaces but found 15

Check failure on line 25 in lint/src/util/misc.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Expected indentation of 6 spaces but found 15
}
return path;
}

Check failure on line 28 in lint/src/util/misc.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Newline required at end of file but not found

Check failure on line 28 in lint/src/util/misc.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Newline required at end of file but not found
12 changes: 1 addition & 11 deletions lint/src/util/theme-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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 +246,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 22531aa

Please sign in to comment.