Skip to content

Commit 494bb4b

Browse files
authored
chore(lint): replace hard-coded separators with path.sep (#26549)
Build on Windows fails due to the hard-coded file path separators (`'/'`) in the eslint rule `invalid-cfn-imports.ts`. The error message is "no such file or directory, open 'C:\aws-cdk\tools\@aws-cdk\pkglint\bin\pkglint.ts\package.json'" as follows: ``` $ npx lerna run build --scope=aws-cdk-lib lerna notice cli v7.1.4 lerna notice filter including "aws-cdk-lib" lerna info filter [ 'aws-cdk-lib' ] × 1/3 dependent project tasks failed (see below) √ 2/3 dependent project tasks succeeded [0 read from cache] ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— > @aws-cdk/pkglint:build yarn run v1.22.19 $ tsc -b && eslint . --ext=.ts && chmod +x bin/pkglint DeprecationWarning: 'originalKeywordKind' has been deprecated since v5.0.0 and will no longer be usable after v5.2.0. Use 'identifierToKeywordKind(identifier)' instead. Oops! Something went wrong! :( ESLint: 7.32.0 Error: Error while loading rule '@aws-cdk/invalid-cfn-imports': ENOENT: no such file or directory, open 'C:\aws-cdk\tools\@aws-cdk\pkglint\bin\pkglint.ts\package.json' Occurred while linting C:\aws-cdk\tools\@aws-cdk\pkglint\bin\pkglint.ts at Object.openSync (node:fs:603:3) at Object.readFileSync (node:fs:471:35) at isAlphaPackage (C:\aws-cdk\tools\@aws-cdk\eslint-plugin\lib\rules\invalid-cfn-imports.js:139:31) at currentFileIsInAlphaPackage (C:\aws-cdk\tools\@aws-cdk\eslint-plugin\lib\rules\invalid-cfn-imports.js:110:16) at Object.create (C:\aws-cdk\tools\@aws-cdk\eslint-plugin\lib\rules\invalid-cfn-imports.js:12:10) at createRuleListeners (C:\aws-cdk\node_modules\eslint\lib\linter\linter.js:765:21) at C:\aws-cdk\node_modules\eslint\lib\linter\linter.js:937:31 at Array.forEach (<anonymous>) at runRules (C:\aws-cdk\node_modules\eslint\lib\linter\linter.js:882:34) at Linter._verifyWithoutProcessors (C:\aws-cdk\node_modules\eslint\lib\linter\linter.js:1181:31) error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. ``` Replace all with `path.sep`, cross-platform separator. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 004e051 commit 494bb4b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/@aws-cdk/eslint-plugin/lib/rules/invalid-cfn-imports.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ function reportErrorIfImportedLocationIsNotValid(context: Rule.RuleContext, node
108108
}
109109

110110
function currentFileIsInAlphaPackage(filename: string): boolean {
111-
const filePathSplit = filename.split('/');
111+
const filePathSplit = filename.split(path.sep);
112112
const awsCdkNamespaceIndex = filePathSplit.findIndex(e => e.match('@aws-cdk'))
113113
if (awsCdkNamespaceIndex !== -1) {
114-
const packageDir = filePathSplit.slice(0, awsCdkNamespaceIndex + 2).join('/');
114+
const packageDir = filePathSplit.slice(0, awsCdkNamespaceIndex + 2).join(path.sep);
115115
return isAlphaPackage(packageDir);
116116
}
117117
return false;
@@ -137,7 +137,7 @@ function getCdkRootDir(filename: string): string | undefined {
137137
}
138138

139139
if (rootDirIndex !== -1) {
140-
return filenameSplit.slice(0, rootDirIndex).join('/');
140+
return filenameSplit.slice(0, rootDirIndex).join(path.sep);
141141
}
142142
return undefined;
143143
}

0 commit comments

Comments
 (0)