Skip to content

Commit

Permalink
added schema description of a rule’s options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Barov committed Sep 2, 2024
1 parent 3434033 commit 76c717f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Adds an ESLint rule to enforce filename conventions for linted files. Allows dif
```bash
$ npm install -D eslint-plugin-filename-rules
```

## Old style config
Add it to your `.eslintrc.js`:

```js
Expand All @@ -28,6 +28,21 @@ module.exports = {
};
```

## Flat config

```js
import fileName from 'eslint-plugin-filename-rules'

{
plugins: {
'filename-rules': fileName,
},
rules: {
'filename-rules/match': [2, 'camelcase']
}
}
```

## Plugin Options

The following built-in values are supported: `pascalcase`/`PascalCase`, `camelcase`/`camelCase`, `snakecase`/`snake_case`, `kebabcase`/`kebab-case`. You can also provide your own regex:
Expand Down
10 changes: 10 additions & 0 deletions lib/common/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ aliases.snake_case = aliases.snakecase;
aliases['kebab-case'] = aliases.kebabcase;

exports.aliases = aliases;
exports.aliasesNames = [
'pascalcase',
'PascalCase',
'camelcase',
'camelCase',
'kebabcase',
'kebab-case',
'snakecase',
'snake_case',
];
15 changes: 15 additions & 0 deletions lib/match.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
const path = require('path');
const { getRegex } = require('./common/getRegex');
const { aliasesNames } = require('./common/aliases');

const meta = {
type: 'layout',
name: 'match',
docs: {
description: 'checks that filenames match a chosen pattern',
},
fixable: false,
messages: {
noMatch: "Filename '{{name}}' does not match {{value}}.",
},
schema: {
type: 'array',
minItems: 1,
maxItems: 2,
oneOf: [
{
items: [{ type: 'string', enum: aliasesNames }],
},
{
items: [{ type: 'object' }],
},
],
},
};

module.exports = {
Expand Down
15 changes: 15 additions & 0 deletions lib/notMatch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
const path = require('path');
const { getRegex } = require('./common/getRegex');
const { aliasesNames} = require('./common/aliases');

const meta = {
type: 'layout',
name: 'not-match',
docs: {
description: 'checks that filenames do not match a chosen pattern',
},
fixable: false,
messages: {
match: "Filename '{{name}}' must not match {{value}}.",
},
schema: {
type: 'array',
minItems: 1,
maxItems: 2,
oneOf: [
{
items: [{ type: 'string', enum: aliasesNames }],
},
{
items: [{ type: 'object' }],
},
],
},
};

module.exports = {
Expand Down

0 comments on commit 76c717f

Please sign in to comment.