Skip to content

Commit 26fca05

Browse files
authored
Added ESLint 9 flat config compatibility for filenames/match-regex and filenames/no-index rules (#38)
* Added ESLint 9 flat config compatibility for filenames rules * ESLint 9 requires rules to define a meta.schema when they accept options, this update adds that support * Added a test that checks whether there is a version change for filename plugin, to make sure this patch is not obsolete in future
1 parent 589f654 commit 26fca05

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

lib/plugins.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ const plugins = {
2020
'ghost-custom': custom
2121
};
2222

23+
// Schemas for rules that don't define them (needed for ESLint 9 flat config)
24+
// Note: match-regex options allow null values (e.g., ['error', '^pattern$', null, true])
25+
const ruleSchemas = {
26+
'filenames/match-regex': [
27+
{type: 'string'},
28+
{type: ['boolean', 'null']},
29+
{type: ['boolean', 'null']}
30+
],
31+
'filenames/no-index': []
32+
};
33+
2334
/**
2435
* Create a rules object from plugin rules.
2536
* Each rule is prefixed by the name of the plugin it comes from
@@ -32,7 +43,19 @@ const getPrefixedPluginRules = () => {
3243

3344
Object.keys(rules).forEach((rule) => {
3445
let name = `${plugin}/${rule}`;
35-
prefixedRules[name] = rules[rule];
46+
let ruleDefinition = rules[rule];
47+
48+
// Wrap function-style rules to add missing schemas for ESLint 9 compatibility
49+
if (typeof ruleDefinition === 'function' && ruleSchemas[name]) {
50+
prefixedRules[name] = {
51+
create: ruleDefinition,
52+
meta: {
53+
schema: ruleSchemas[name]
54+
}
55+
};
56+
} else {
57+
prefixedRules[name] = ruleDefinition;
58+
}
3659
});
3760
});
3861

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-ghost",
3-
"version": "3.4.1",
3+
"version": "3.4.2",
44
"description": "Shared eslint configurations",
55
"author": "Ghost Foundation",
66
"homepage": "https://github.com/TryGhost/eslint-plugin-ghost",

test/filenames-schema.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const assert = require('node:assert/strict');
2+
const {test} = require('node:test');
3+
const {getPrefixedPluginRules} = require('../lib/plugins');
4+
const filenamesPackage = require('eslint-plugin-filenames-ts/package.json');
5+
6+
const rules = getPrefixedPluginRules();
7+
8+
test('eslint-plugin-filenames-ts version check', function () {
9+
assert.equal(filenamesPackage.version, '1.3.2',
10+
'eslint-plugin-filenames-ts version changed - verify schemas in lib/plugins.js are still correct or if the plugin now provides its own');
11+
});
12+
13+
test('filenames/match-regex should be an object-style rule with schema', function () {
14+
const rule = rules['filenames/match-regex'];
15+
16+
assert.equal(typeof rule, 'object');
17+
assert.equal(typeof rule.create, 'function');
18+
assert.ok(rule.meta, 'rule should have meta property');
19+
assert.ok(Array.isArray(rule.meta.schema), 'rule should have meta.schema array');
20+
21+
const schema = rule.meta.schema;
22+
23+
// Option 1: regex pattern string
24+
assert.deepEqual(schema[0], {type: 'string'});
25+
// Option 2: ignoreExporting (boolean or null)
26+
assert.deepEqual(schema[1], {type: ['boolean', 'null']});
27+
// Option 3: ignoreExportingClass (boolean or null)
28+
assert.deepEqual(schema[2], {type: ['boolean', 'null']});
29+
});
30+
31+
test('filenames/no-index should be an object-style rule with empty schema', function () {
32+
const rule = rules['filenames/no-index'];
33+
34+
assert.equal(typeof rule, 'object');
35+
assert.equal(typeof rule.create, 'function');
36+
assert.ok(rule.meta, 'rule should have meta property');
37+
assert.ok(Array.isArray(rule.meta.schema), 'rule should have meta.schema array');
38+
assert.equal(rule.meta.schema.length, 0, 'no-index takes no options');
39+
});

0 commit comments

Comments
 (0)