eslint-plugin-filename-rules
Advanced tools
Comparing version 1.2.0 to 1.3.0
const match = require('./match'); | ||
const notMatch = require('./notMatch'); | ||
@@ -6,3 +7,4 @@ module.exports = { | ||
match, | ||
'not-match': notMatch, | ||
}, | ||
}; |
const path = require('path'); | ||
const { getRegex } = require('./common/getRegex'); | ||
@@ -14,27 +15,2 @@ const meta = { | ||
const aliases = { | ||
pascalcase: /^[A-Z]([A-Z0-9]*[a-z]+)+[A-Z0-9]*(?:\..*)?$/, | ||
camelcase: /^[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?(?:\..*)?$/, | ||
snakecase: /^([a-z]+_)*[a-z]+(?:\..*)?$/, | ||
kebabcase: /^([a-z]+-)*[a-z]+(?:\..*)?$/, | ||
}; | ||
aliases.PascalCase = aliases.pascalcase; | ||
aliases.camelCase = aliases.camelcase; | ||
aliases.snake_case = aliases.snakecase; | ||
aliases['kebab-case'] = aliases.kebabcase; | ||
const getRegex = (value, filename) => { | ||
if (value instanceof RegExp) return [value, value.toString()]; | ||
if (typeof value === 'string') { | ||
const regex = aliases[value]; | ||
if (!regex) throw new Error(`Unrecognized option "${value}"`); | ||
return [regex, value]; | ||
} | ||
const extension = filename.substr(filename.lastIndexOf('.')); | ||
const valueForExtension = value[extension]; | ||
return valueForExtension ? getRegex(valueForExtension) : []; | ||
}; | ||
module.exports = { | ||
@@ -45,6 +21,7 @@ meta, | ||
const filename = context.getFilename(); | ||
const basename = path.basename(filename); | ||
const [regex, regexStr] = getRegex(context.options[0], basename); | ||
const includePath = !!(context.options[0] || {}).includePath; | ||
const name = includePath ? filename : path.basename(filename); | ||
const [regex, regexStr] = getRegex(context.options[0], name); | ||
if (!regex) return; | ||
if (!regex.test(basename)) { | ||
if (!regex.test(name)) { | ||
context.report({ | ||
@@ -54,3 +31,3 @@ node, | ||
data: { | ||
name: basename, | ||
name, | ||
value: regexStr, | ||
@@ -57,0 +34,0 @@ }, |
{ | ||
"name": "eslint-plugin-filename-rules", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Enforce filename conventions for linted files", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7701
8
108