Skip to content

Also test separator unified path #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rules/invalid-regex-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function createReplacement(replacement) {
return () => undefined
}

function checkPatterns(fileName, source, patterns, report) {
patterns.forEach(pattern => shouldCheck(pattern.files, fileName) &&
function checkPatterns(fileNames, source, patterns, report) {
patterns.forEach(pattern => shouldCheck(pattern.files, fileNames) &&
checkRegex(source, pattern, createReplacement(pattern.details.replacement), report))
}

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/required-regex-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const { shouldCheck } = require('../utils/check-utils.js')

const { REGEX_FLAGS_FIELD_DEFINITION, FILES_FIELD_DEFINITION } = require('./common-fields-definitions.js')

function checkPatterns(fileName, source, patterns, report, node) {
function checkPatterns(fileNames, source, patterns, report, node) {
patterns.forEach(pattern => {
if (shouldCheck(pattern.files, fileName) && !pattern.regex.test(source)) {
if (shouldCheck(pattern.files, fileNames) && !pattern.regex.test(source)) {
report({
node,
message: formatReportMessage(
Expand Down
9 changes: 6 additions & 3 deletions lib/utils/check-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

/**
* @param {{ignore: RegExp, inspect: RegExp} | false} [files] Patterns that indicate which files to inspect and which to ignore.
* @param {string} fileName Name of the file.
* @param {[string, string]} fileNames Name of the file in array, the original path followed by a separator unified path.
* @returns {boolean} true if the file should be checked.
*/
module.exports.shouldCheck = function (files, fileName) {
return !files || (!files.ignore.test(fileName) && files.inspect.test(fileName))
module.exports.shouldCheck = function (files, fileNames) {
const [fileName, unfFileName] = fileNames
return !files ||
(!(files.ignore.test(fileName) || files.ignore.test(unfFileName)) &&
(files.inspect.test(fileName) || files.inspect.test(unfFileName)))
}
6 changes: 4 additions & 2 deletions lib/utils/create-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module.exports.buildCreateFunction = function (checkPatterns) {
return {
Program: function (node) {
const fileName = context.getFilename()
if (!options.ignoreFilePattern.test(context.getFilename())) {
checkPatterns(fileName, context.getSourceCode(node).getText(), options.patterns, context.report, node)
const unfFileName = fileName.replaceAll('\\', '/')
const fileNames = [fileName, unfFileName]
if (!(options.ignoreFilePattern.test(fileName) && options.ignoreFilePattern.test(unfFileName))) {
checkPatterns(fileNames, context.getSourceCode(node).getText(), options.patterns, context.report, node)
}
}
}
Expand Down