eslint-plugin-validate-filename
raw JSON → 1.2.0 verified Sat Apr 25 auth: no javascript
ESLint plugin with rules to enforce file naming conventions. Current version 1.2.0 (released 2025). Supports ESLint v7+. Features include folder-based case enforcement (camel, pascal, snake, kebab, flat), regex pattern matching, exclusion patterns, and extension whitelisting via limit-extensions rule. Differentiators: per-folder rules, exclusion support, and Next.js integration examples. Maintenance-oriented release cadence.
Common errors
error ESLint: Error while loading rule 'validate-filename/naming-rules': Rule is not found ↓
cause Plugin not added to plugins array or incorrectly configured in flat config.
fix
Ensure plugin is registered: in flat config use plugins: { 'validate-filename': validateFilename }.
error Cannot find module 'eslint-plugin-validate-filename' ↓
cause Package not installed or not in node_modules.
fix
Run 'npm install --save-dev eslint-plugin-validate-filename'.
error Invalid option 'case' - must be one of camel, pascal, snake, kebab, flat ↓
cause Typo or unsupported case value.
fix
Use one of: camel, pascal, snake, kebab, flat.
error target is not a valid glob pattern ↓
cause target uses regex or invalid glob syntax.
fix
Use proper glob patterns like '**/components/**'.
Warnings
breaking ESLint v9 requires flat config; plugin must be imported as object. ↓
fix Use import validateFilename from 'eslint-plugin-validate-filename'; and set plugins: { 'validate-filename': validateFilename }.
deprecated Rule naming-rules 'case' property is optional since v1.2.0; if omitted, no case enforcement occurs. ↓
fix Explicitly set 'case' to required value if case enforcement is intended.
gotcha limit-extensions 'target' expects a glob pattern, not a regex; common mistake using regex like '/schemas/'. ↓
fix Use glob patterns such as '**/schemas/**'.
gotcha Patterns in naming-rules are regular expressions, not glob; ensure proper escaping. ↓
fix For literal '.' use '\\.' in regex patterns.
breaking Node.js >=18.18.0 required starting from v1.0.0. ↓
fix Upgrade Node.js to version 18.18.0 or later.
Install
npm install eslint-plugin-validate-filename yarn add eslint-plugin-validate-filename pnpm add eslint-plugin-validate-filename Imports
- default export wrong
const validateFilename = require('eslint-plugin-validate-filename')correctimport validateFilename from 'eslint-plugin-validate-filename' - rules
import { rules } from 'eslint-plugin-validate-filename' - Plugin config wrong
plugins: ['validate-filename'] // Not valid for flat configcorrectimport validateFilename from 'eslint-plugin-validate-filename'; plugins: { 'validate-filename': validateFilename }
Quickstart
// .eslintrc.js (legacy)
module.exports = {
plugins: ['validate-filename'],
rules: {
'validate-filename/naming-rules': ['error', {
rules: [
{ case: 'pascal', target: '**/components/**' },
{ case: 'camel', target: '**/hooks/**', patterns: '^use' }
]
}],
'validate-filename/limit-extensions': ['error', {
rules: [
{ target: '**/hooks/**', extensions: ['.ts', '.tsx'] }
]
}]
}
};
// eslint.config.js (flat config)
import validateFilename from 'eslint-plugin-validate-filename';
export default [
{
plugins: { 'validate-filename': validateFilename },
rules: {
'validate-filename/naming-rules': ['error', {
rules: [
{ case: 'pascal', target: '**/components/**' },
{ case: 'camel', target: '**/hooks/**', patterns: '^use' }
]
}],
'validate-filename/limit-extensions': ['error', {
rules: [
{ target: '**/hooks/**', extensions: ['.ts', '.tsx'] }
]
}]
}
}
];