Skip to content

Commit 580b0a1

Browse files
committed
fix: using file path from respository root as lint target
1 parent 0e85d34 commit 580b0a1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/rules/filename-naming-convention.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
*/
55
'use strict';
66

7-
const { getFilename, getBasename } = require('../utils/filename');
7+
const {
8+
getFilename,
9+
getBasename,
10+
getPathFromRepositoryRoot,
11+
} = require('../utils/filename');
812
const {
913
checkSettings,
1014
namingPatternValidator,
@@ -65,13 +69,16 @@ module.exports = {
6569
return;
6670
}
6771

68-
const filenameWithPath = context.getFilename();
69-
const filename = getFilename(filenameWithPath);
72+
const pathFromRepositoryRoot = getPathFromRepositoryRoot(
73+
context.getPhysicalFilename(),
74+
context.getCwd()
75+
);
76+
const filename = getFilename(pathFromRepositoryRoot);
7077

7178
for (const [fexPattern, namingPattern] of Object.entries(rules)) {
7279
const matchResult =
7380
matchRule(
74-
filenameWithPath,
81+
pathFromRepositoryRoot,
7582
fexPattern,
7683
getBasename(filename, ignoreMiddleExtensions),
7784
namingPattern

lib/utils/filename.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ const getSubPaths = (path) => {
5959
return subPaths;
6060
};
6161

62+
/**
63+
* @type {string} path from repository root
64+
* @param {string} fullPath filename with full path
65+
* @param {string} repositoryRoot path of repository root
66+
*/
67+
const getPathFromRepositoryRoot = (fullPath, repositoryRoot) =>
68+
fullPath.replace(`${repositoryRoot}/`, '');
69+
6270
module.exports = {
6371
getFolderPath,
6472
getFilename,
6573
getBasename,
6674
getSubPaths,
6775
getAllFolders,
76+
getPathFromRepositoryRoot,
6877
};

0 commit comments

Comments
 (0)