Skip to content

Commit 1e9332b

Browse files
committed
refactor: extract regexp
1 parent 35ac4ae commit 1e9332b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/constants/regex.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
*/
1010
const PREFINED_MATCH_SYNTAX_REGEXP = /^<(\d+)>$/;
1111

12+
/**
13+
* @example C:\
14+
*/
15+
const WINDOWS_DRIVE_LETTER_REGEXP = /^[A-Za-z]:\\/;
16+
1217
module.exports = {
1318
PREFINED_MATCH_SYNTAX_REGEXP,
19+
WINDOWS_DRIVE_LETTER_REGEXP,
1420
};

lib/utils/filename.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const path = require('path');
88
const { pipe, isNotEmpty } = require('./utility');
9+
const { WINDOWS_DRIVE_LETTER_REGEXP } = require('../constants/regex');
910

1011
/**
1112
* @returns {string} filename without path
@@ -82,7 +83,7 @@ const toPosixPath = (p) => p.split(path.sep).join(path.posix.sep);
8283
* @returns {string} file path without drive letter on windows
8384
* @param {string} p file path on windows
8485
*/
85-
const removeDriveLetter = (p) => p.replace(/^[A-Za-z]:\\/, '');
86+
const removeDriveLetter = (p) => p.replace(WINDOWS_DRIVE_LETTER_REGEXP, '');
8687

8788
/** @typedef {module:eslint} ESLint */
8889
/**

0 commit comments

Comments
 (0)