Skip to content

Commit ca44623

Browse files
committed
feat(linter): add schema for eslint/no-empty-function (#22988)
1 parent 43eb04d commit ca44623

4 files changed

Lines changed: 343 additions & 5 deletions

File tree

apps/oxlint/src-js/package/config.generated.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ export type Mode3 = "always" | "never";
9090
export type JestFnType = "hook" | "describe" | "test" | "expect" | "jest" | "unknown";
9191
export type LogicalAssignmentOperatorsMode = "always" | "never";
9292
export type CountThis = "always" | "never" | "except-void";
93+
/**
94+
* Kinds of functions that can be allowed to be empty.
95+
*/
96+
export type AllowKind =
97+
| "functions"
98+
| "arrowFunctions"
99+
| "generatorFunctions"
100+
| "methods"
101+
| "generatorMethods"
102+
| "getters"
103+
| "setters"
104+
| "constructors"
105+
| "asyncFunctions"
106+
| "asyncMethods"
107+
| "privateConstructors"
108+
| "protectedConstructors"
109+
| "decoratedFunctions"
110+
| "overrideMethods";
93111
export type ShorthandType = "always" | "methods" | "properties" | "consistent" | "consistent-as-needed" | "never";
94112
/**
95113
* A forbidden prop, either as a plain prop name string or with options.
@@ -893,7 +911,7 @@ export interface DummyRuleMap {
893911
"no-else-return"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoElseReturn];
894912
"no-empty"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoEmpty];
895913
"no-empty-character-class"?: RuleNoConfig;
896-
"no-empty-function"?: DummyRule;
914+
"no-empty-function"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoEmptyFunctionConfig];
897915
"no-empty-pattern"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoEmptyPattern];
898916
"no-empty-static-block"?: RuleNoConfig;
899917
"no-eq-null"?: RuleNoConfig;
@@ -2415,6 +2433,29 @@ export interface NoEmpty {
24152433
*/
24162434
allowEmptyCatch?: boolean;
24172435
}
2436+
export interface NoEmptyFunctionConfig {
2437+
/**
2438+
* Types of functions that are allowed to be empty.
2439+
*
2440+
* By default, no function kinds are allowed to be empty, but this option can be used to
2441+
* permit specific kinds of functions.
2442+
*
2443+
* Example:
2444+
* ```json
2445+
* {
2446+
* "no-empty-function": [
2447+
* "error",
2448+
* {
2449+
* "allow": [
2450+
* "constructors"
2451+
* ]
2452+
* }
2453+
* ]
2454+
* }
2455+
* ```
2456+
*/
2457+
allow?: AllowKind[];
2458+
}
24182459
export interface NoEmptyPattern {
24192460
/**
24202461
* When set to `true`, this rule allows empty object patterns used directly as function

crates/oxc_linter/src/utils/schemars.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use crate::rules::RuleEnum;
1313
/// These should return the DummyRule struct/schema instead of the actual rule struct/schema,
1414
/// until we verify that the rule's schema is valid and can be generated by schemars.
1515
#[cfg(feature = "ruledocs")]
16-
const NO_VERIFIED_VALID_SCHEMA: [&str; 110] = [
16+
const NO_VERIFIED_VALID_SCHEMA: [&str; 109] = [
1717
"eslint/func-name-matching",
18-
"eslint/no-empty-function",
1918
"eslint/no-constant-condition",
2019
"eslint/no-inner-declarations",
2120
"eslint/no-magic-numbers",

npm/oxlint/configuration_schema.json

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,124 @@
285285
},
286286
"additionalProperties": false
287287
},
288+
"AllowKind": {
289+
"description": "Kinds of functions that can be allowed to be empty.",
290+
"oneOf": [
291+
{
292+
"description": "Allow empty regular functions.\n\n```js\nfunction foo() {}\n```",
293+
"type": "string",
294+
"enum": [
295+
"functions"
296+
],
297+
"markdownDescription": "Allow empty regular functions.\n\n```js\nfunction foo() {}\n```"
298+
},
299+
{
300+
"description": "Allow empty arrow functions.\n\n```js\nconst foo = () => {};\n```",
301+
"type": "string",
302+
"enum": [
303+
"arrowFunctions"
304+
],
305+
"markdownDescription": "Allow empty arrow functions.\n\n```js\nconst foo = () => {};\n```"
306+
},
307+
{
308+
"description": "Allow empty generator functions.\n\n```js\nfunction* foo() {}\n```",
309+
"type": "string",
310+
"enum": [
311+
"generatorFunctions"
312+
],
313+
"markdownDescription": "Allow empty generator functions.\n\n```js\nfunction* foo() {}\n```"
314+
},
315+
{
316+
"description": "Allow empty methods.\n\n```js\nclass Foo {\nbar() {}\n}\n```",
317+
"type": "string",
318+
"enum": [
319+
"methods"
320+
],
321+
"markdownDescription": "Allow empty methods.\n\n```js\nclass Foo {\nbar() {}\n}\n```"
322+
},
323+
{
324+
"description": "Allow empty generator methods.\n\n```js\nclass Foo {\n*bar() {}\n}\n```",
325+
"type": "string",
326+
"enum": [
327+
"generatorMethods"
328+
],
329+
"markdownDescription": "Allow empty generator methods.\n\n```js\nclass Foo {\n*bar() {}\n}\n```"
330+
},
331+
{
332+
"description": "Allow empty getters.\n\n```js\nclass Foo {\nget bar() {}\n}\n```",
333+
"type": "string",
334+
"enum": [
335+
"getters"
336+
],
337+
"markdownDescription": "Allow empty getters.\n\n```js\nclass Foo {\nget bar() {}\n}\n```"
338+
},
339+
{
340+
"description": "Allow empty setters.\n\n```js\nclass Foo {\nset bar(value) {}\n}\n```",
341+
"type": "string",
342+
"enum": [
343+
"setters"
344+
],
345+
"markdownDescription": "Allow empty setters.\n\n```js\nclass Foo {\nset bar(value) {}\n}\n```"
346+
},
347+
{
348+
"description": "Allow empty constructors.\n\n```js\nclass Foo {\nconstructor() {}\n}\n```",
349+
"type": "string",
350+
"enum": [
351+
"constructors"
352+
],
353+
"markdownDescription": "Allow empty constructors.\n\n```js\nclass Foo {\nconstructor() {}\n}\n```"
354+
},
355+
{
356+
"description": "Allow empty async functions.\n\n```js\nasync function foo() {}\n```",
357+
"type": "string",
358+
"enum": [
359+
"asyncFunctions"
360+
],
361+
"markdownDescription": "Allow empty async functions.\n\n```js\nasync function foo() {}\n```"
362+
},
363+
{
364+
"description": "Allow empty async methods.\n\n```js\nclass Foo {\nasync bar() {}\n}\n```",
365+
"type": "string",
366+
"enum": [
367+
"asyncMethods"
368+
],
369+
"markdownDescription": "Allow empty async methods.\n\n```js\nclass Foo {\nasync bar() {}\n}\n```"
370+
},
371+
{
372+
"description": "Allow empty private constructors.\n\n```ts\nclass Foo {\nprivate constructor() {}\n}\n```",
373+
"type": "string",
374+
"enum": [
375+
"privateConstructors"
376+
],
377+
"markdownDescription": "Allow empty private constructors.\n\n```ts\nclass Foo {\nprivate constructor() {}\n}\n```"
378+
},
379+
{
380+
"description": "Allow empty protected constructors.\n\n```ts\nclass Foo {\nprotected constructor() {}\n}\n```",
381+
"type": "string",
382+
"enum": [
383+
"protectedConstructors"
384+
],
385+
"markdownDescription": "Allow empty protected constructors.\n\n```ts\nclass Foo {\nprotected constructor() {}\n}\n```"
386+
},
387+
{
388+
"description": "Allow empty decorated functions.\n\n```js\nclass Foo {\n@decorator()\nbar() {}\n}\n```",
389+
"type": "string",
390+
"enum": [
391+
"decoratedFunctions"
392+
],
393+
"markdownDescription": "Allow empty decorated functions.\n\n```js\nclass Foo {\n@decorator()\nbar() {}\n}\n```"
394+
},
395+
{
396+
"description": "Allow empty override methods.\n\n```ts\nclass Foo extends Base {\noverride bar() {}\n}\n```",
397+
"type": "string",
398+
"enum": [
399+
"overrideMethods"
400+
],
401+
"markdownDescription": "Allow empty override methods.\n\n```ts\nclass Foo extends Base {\noverride bar() {}\n}\n```"
402+
}
403+
],
404+
"markdownDescription": "Kinds of functions that can be allowed to be empty."
405+
},
288406
"AllowWarnDeny": {
289407
"oneOf": [
290408
{
@@ -2902,7 +3020,24 @@
29023020
"$ref": "#/definitions/RuleNoConfig"
29033021
},
29043022
"no-empty-function": {
2905-
"$ref": "#/definitions/DummyRule"
3023+
"anyOf": [
3024+
{
3025+
"$ref": "#/definitions/AllowWarnDeny"
3026+
},
3027+
{
3028+
"type": "array",
3029+
"items": [
3030+
{
3031+
"$ref": "#/definitions/AllowWarnDeny"
3032+
},
3033+
{
3034+
"$ref": "#/definitions/NoEmptyFunctionConfig"
3035+
}
3036+
],
3037+
"maxItems": 2,
3038+
"minItems": 1
3039+
}
3040+
]
29063041
},
29073042
"no-empty-pattern": {
29083043
"anyOf": [
@@ -9564,6 +9699,20 @@
95649699
},
95659700
"additionalProperties": false
95669701
},
9702+
"NoEmptyFunctionConfig": {
9703+
"type": "object",
9704+
"properties": {
9705+
"allow": {
9706+
"description": "Types of functions that are allowed to be empty.\n\nBy default, no function kinds are allowed to be empty, but this option can be used to\npermit specific kinds of functions.\n\nExample:\n```json\n{\n\"no-empty-function\": [\"error\", { \"allow\": [\"constructors\"] }]\n}\n```",
9707+
"type": "array",
9708+
"items": {
9709+
"$ref": "#/definitions/AllowKind"
9710+
},
9711+
"markdownDescription": "Types of functions that are allowed to be empty.\n\nBy default, no function kinds are allowed to be empty, but this option can be used to\npermit specific kinds of functions.\n\nExample:\n```json\n{\n\"no-empty-function\": [\"error\", { \"allow\": [\"constructors\"] }]\n}\n```"
9712+
}
9713+
},
9714+
"additionalProperties": false
9715+
},
95679716
"NoEmptyInterface": {
95689717
"type": "object",
95699718
"properties": {

0 commit comments

Comments
 (0)