File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,3 +14,15 @@ export function match(rangeA: number[], rangeB: number[]) {
1414export 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+ }
Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ import {
1616 isPartOfViewChild ,
1717} from './angular' ;
1818import {
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-
259247export function allThemeableComponents ( ) : ThemeableComponentRegistryEntry [ ] {
260248 themeableComponents . initialize ( ) ;
261249 return [ ...themeableComponents . entries ] ;
Original file line number Diff line number Diff 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
1518export 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+ */
1724export 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
2330export function getSourceCode ( context : AnyRuleContext ) : TSESLint . SourceCode {
You can’t perform that action at this time.
0 commit comments