From 76c717fbe3abfa06675feca6cf298f665bee3393 Mon Sep 17 00:00:00 2001 From: Jaroslav Barov Date: Mon, 2 Sep 2024 14:36:59 +0300 Subject: [PATCH] =?UTF-8?q?added=20schema=20description=20of=20a=20rule?= =?UTF-8?q?=E2=80=99s=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 ++++++++++++++++- lib/common/aliases.js | 10 ++++++++++ lib/match.js | 15 +++++++++++++++ lib/notMatch.js | 15 +++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fbc1ae..3317426 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: diff --git a/lib/common/aliases.js b/lib/common/aliases.js index e22fe30..22ad1e1 100644 --- a/lib/common/aliases.js +++ b/lib/common/aliases.js @@ -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', +]; diff --git a/lib/match.js b/lib/match.js index f1b4e3b..d14d506 100644 --- a/lib/match.js +++ b/lib/match.js @@ -1,8 +1,10 @@ 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', }, @@ -10,6 +12,19 @@ const meta = { 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 = { diff --git a/lib/notMatch.js b/lib/notMatch.js index cf64e5d..b52a163 100644 --- a/lib/notMatch.js +++ b/lib/notMatch.js @@ -1,8 +1,10 @@ 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', }, @@ -10,6 +12,19 @@ const meta = { 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 = {