@bemoje/eslint 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +101 -0
- package/lib/index.d.cts +5 -0
- package/lib/index.d.ts +5 -0
- package/lib/lib/createRule.cjs +10 -0
- package/lib/lib/createRule.d.cts +18 -0
- package/lib/lib/createRule.d.ts +18 -0
- package/lib/lib/createRule.js +8 -0
- package/lib/lib/eslintPluginBemoje.cjs +101 -0
- package/{index.d.ts → lib/lib/eslintPluginBemoje.d.cts} +1 -28
- package/lib/lib/eslintPluginBemoje.d.ts +38 -0
- package/lib/lib/eslintPluginBemoje.js +99 -0
- package/lib/rules/noBlankLineBetweenCommentAndDeclaration.cjs +72 -0
- package/lib/rules/noBlankLineBetweenCommentAndDeclaration.d.cts +14 -0
- package/lib/rules/noBlankLineBetweenCommentAndDeclaration.d.ts +14 -0
- package/lib/rules/noBlankLineBetweenCommentAndDeclaration.js +70 -0
- package/package.json +72 -21
- /package/{index.mjs → lib/index.js} +0 -0
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@typescript-eslint/utils');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var createRule = utils.ESLintUtils.RuleCreator((name) => {
|
|
8
|
+
return `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`;
|
|
9
|
+
});
|
|
10
|
+
var noBlankLineBetweenCommentAndDeclaration = createRule({
|
|
11
|
+
name: "no-blank-line-between-comment-and-declaration",
|
|
12
|
+
meta: {
|
|
13
|
+
fixable: "whitespace",
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Consistant whitespace ",
|
|
16
|
+
recommended: true
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
"no-blank-line-between-comment-and-declaration": "Block comments for a declaration must not leave blank lines between them."
|
|
20
|
+
},
|
|
21
|
+
type: "problem",
|
|
22
|
+
schema: []
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [
|
|
25
|
+
"error"
|
|
26
|
+
],
|
|
27
|
+
create(context) {
|
|
28
|
+
return {
|
|
29
|
+
Program(program) {
|
|
30
|
+
program.comments?.forEach((comment) => {
|
|
31
|
+
if (comment.type !== utils.AST_TOKEN_TYPES.Block) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const nextToken = context.sourceCode.getTokenAfter(comment);
|
|
38
|
+
if (!nextToken) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const actualNextTokenStartLine = nextToken.loc.start.line;
|
|
42
|
+
const expectedTokenStartLine = comment.loc.end.line + 1;
|
|
43
|
+
if (!(actualNextTokenStartLine > expectedTokenStartLine)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const lineBeforeNextToken = context.sourceCode.lines[nextToken.loc.start.line - 1 - 1];
|
|
47
|
+
const hasLineCommentBetween = lineBeforeNextToken.trim().startsWith("//");
|
|
48
|
+
if (hasLineCommentBetween) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
return context.report({
|
|
52
|
+
node: program,
|
|
53
|
+
messageId: "no-blank-line-between-comment-and-declaration",
|
|
54
|
+
fix(fixer) {
|
|
55
|
+
const start = comment.range[0];
|
|
56
|
+
const end = nextToken.range[1];
|
|
57
|
+
const rangeCode = context.sourceCode.text.slice(start, end);
|
|
58
|
+
const rangeCodeFixed = rangeCode.replaceAll(/\*\/\n\n+/gi, "*/\n");
|
|
59
|
+
return fixer.replaceTextRange([
|
|
60
|
+
start,
|
|
61
|
+
end
|
|
62
|
+
], rangeCodeFixed);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// src/lib/eslintPluginBemoje.ts
|
|
72
|
+
function eslintPluginBemoje() {
|
|
73
|
+
const rules = {
|
|
74
|
+
"no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration
|
|
75
|
+
};
|
|
76
|
+
const plugins = {
|
|
77
|
+
get "eslint-plugin-bemoje"() {
|
|
78
|
+
return eslintPluginBemoje();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
configs: {
|
|
83
|
+
get recommended() {
|
|
84
|
+
return {
|
|
85
|
+
plugins,
|
|
86
|
+
rules
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
meta: {
|
|
91
|
+
name: "eslint-plugin-bemoje",
|
|
92
|
+
version: "1.0.1"
|
|
93
|
+
},
|
|
94
|
+
rules
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
__name(eslintPluginBemoje, "eslintPluginBemoje");
|
|
98
|
+
|
|
99
|
+
exports.createRule = createRule;
|
|
100
|
+
exports.eslintPluginBemoje = eslintPluginBemoje;
|
|
101
|
+
exports.noBlankLineBetweenCommentAndDeclaration = noBlankLineBetweenCommentAndDeclaration;
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createRule } from './lib/createRule.cjs';
|
|
2
|
+
export { eslintPluginBemoje } from './lib/eslintPluginBemoje.cjs';
|
|
3
|
+
export { noBlankLineBetweenCommentAndDeclaration } from './rules/noBlankLineBetweenCommentAndDeclaration.cjs';
|
|
4
|
+
import '@typescript-eslint/utils';
|
|
5
|
+
import '@typescript-eslint/utils/ts-eslint';
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createRule } from './lib/createRule.js';
|
|
2
|
+
export { eslintPluginBemoje } from './lib/eslintPluginBemoje.js';
|
|
3
|
+
export { noBlankLineBetweenCommentAndDeclaration } from './rules/noBlankLineBetweenCommentAndDeclaration.js';
|
|
4
|
+
import '@typescript-eslint/utils';
|
|
5
|
+
import '@typescript-eslint/utils/ts-eslint';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@typescript-eslint/utils');
|
|
4
|
+
|
|
5
|
+
// src/lib/createRule.ts
|
|
6
|
+
var createRule = utils.ESLintUtils.RuleCreator((name) => {
|
|
7
|
+
return `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
exports.createRule = createRule;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper to create an ESLint rule with a consistent format.
|
|
5
|
+
*/
|
|
6
|
+
declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, {
|
|
7
|
+
description: string;
|
|
8
|
+
recommended?: boolean;
|
|
9
|
+
requiresTypeChecking?: boolean;
|
|
10
|
+
}>>) => ESLintUtils.RuleModule<MessageIds, Options, {
|
|
11
|
+
description: string;
|
|
12
|
+
recommended?: boolean;
|
|
13
|
+
requiresTypeChecking?: boolean;
|
|
14
|
+
}, ESLintUtils.RuleListener> & {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { createRule };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper to create an ESLint rule with a consistent format.
|
|
5
|
+
*/
|
|
6
|
+
declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, {
|
|
7
|
+
description: string;
|
|
8
|
+
recommended?: boolean;
|
|
9
|
+
requiresTypeChecking?: boolean;
|
|
10
|
+
}>>) => ESLintUtils.RuleModule<MessageIds, Options, {
|
|
11
|
+
description: string;
|
|
12
|
+
recommended?: boolean;
|
|
13
|
+
requiresTypeChecking?: boolean;
|
|
14
|
+
}, ESLintUtils.RuleListener> & {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { createRule };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@typescript-eslint/utils');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var createRule = utils.ESLintUtils.RuleCreator((name) => {
|
|
8
|
+
return `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// src/rules/noBlankLineBetweenCommentAndDeclaration.ts
|
|
12
|
+
var noBlankLineBetweenCommentAndDeclaration = createRule({
|
|
13
|
+
name: "no-blank-line-between-comment-and-declaration",
|
|
14
|
+
meta: {
|
|
15
|
+
fixable: "whitespace",
|
|
16
|
+
docs: {
|
|
17
|
+
description: "Consistant whitespace ",
|
|
18
|
+
recommended: true
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
"no-blank-line-between-comment-and-declaration": "Block comments for a declaration must not leave blank lines between them."
|
|
22
|
+
},
|
|
23
|
+
type: "problem",
|
|
24
|
+
schema: []
|
|
25
|
+
},
|
|
26
|
+
defaultOptions: [
|
|
27
|
+
"error"
|
|
28
|
+
],
|
|
29
|
+
create(context) {
|
|
30
|
+
return {
|
|
31
|
+
Program(program) {
|
|
32
|
+
program.comments?.forEach((comment) => {
|
|
33
|
+
if (comment.type !== utils.AST_TOKEN_TYPES.Block) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const nextToken = context.sourceCode.getTokenAfter(comment);
|
|
40
|
+
if (!nextToken) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const actualNextTokenStartLine = nextToken.loc.start.line;
|
|
44
|
+
const expectedTokenStartLine = comment.loc.end.line + 1;
|
|
45
|
+
if (!(actualNextTokenStartLine > expectedTokenStartLine)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const lineBeforeNextToken = context.sourceCode.lines[nextToken.loc.start.line - 1 - 1];
|
|
49
|
+
const hasLineCommentBetween = lineBeforeNextToken.trim().startsWith("//");
|
|
50
|
+
if (hasLineCommentBetween) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return context.report({
|
|
54
|
+
node: program,
|
|
55
|
+
messageId: "no-blank-line-between-comment-and-declaration",
|
|
56
|
+
fix(fixer) {
|
|
57
|
+
const start = comment.range[0];
|
|
58
|
+
const end = nextToken.range[1];
|
|
59
|
+
const rangeCode = context.sourceCode.text.slice(start, end);
|
|
60
|
+
const rangeCodeFixed = rangeCode.replaceAll(/\*\/\n\n+/gi, "*/\n");
|
|
61
|
+
return fixer.replaceTextRange([
|
|
62
|
+
start,
|
|
63
|
+
end
|
|
64
|
+
], rangeCodeFixed);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// src/lib/eslintPluginBemoje.ts
|
|
74
|
+
function eslintPluginBemoje() {
|
|
75
|
+
const rules = {
|
|
76
|
+
"no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration
|
|
77
|
+
};
|
|
78
|
+
const plugins = {
|
|
79
|
+
get "eslint-plugin-bemoje"() {
|
|
80
|
+
return eslintPluginBemoje();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
configs: {
|
|
85
|
+
get recommended() {
|
|
86
|
+
return {
|
|
87
|
+
plugins,
|
|
88
|
+
rules
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
meta: {
|
|
93
|
+
name: "eslint-plugin-bemoje",
|
|
94
|
+
version: "1.0.1"
|
|
95
|
+
},
|
|
96
|
+
rules
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
__name(eslintPluginBemoje, "eslintPluginBemoje");
|
|
100
|
+
|
|
101
|
+
exports.eslintPluginBemoje = eslintPluginBemoje;
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
* Helper to create an ESLint rule with a consistent format.
|
|
6
|
-
*/
|
|
7
|
-
declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, {
|
|
8
|
-
description: string;
|
|
9
|
-
recommended?: boolean;
|
|
10
|
-
requiresTypeChecking?: boolean;
|
|
11
|
-
}>>) => ESLintUtils.RuleModule<MessageIds, Options, {
|
|
12
|
-
description: string;
|
|
13
|
-
recommended?: boolean;
|
|
14
|
-
requiresTypeChecking?: boolean;
|
|
15
|
-
}, ESLintUtils.RuleListener> & {
|
|
16
|
-
name: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
3
|
/**
|
|
20
4
|
* ESLint plugin for Bemoje projects.
|
|
21
5
|
*/
|
|
@@ -51,15 +35,4 @@ declare function eslintPluginBemoje(): {
|
|
|
51
35
|
};
|
|
52
36
|
};
|
|
53
37
|
|
|
54
|
-
|
|
55
|
-
* Enforce no blank lines between block comments and the next declaration.
|
|
56
|
-
*/
|
|
57
|
-
declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
|
|
58
|
-
description: string;
|
|
59
|
-
recommended?: boolean;
|
|
60
|
-
requiresTypeChecking?: boolean;
|
|
61
|
-
}, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
62
|
-
name: string;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration };
|
|
38
|
+
export { eslintPluginBemoje };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ESLint plugin for Bemoje projects.
|
|
5
|
+
*/
|
|
6
|
+
declare function eslintPluginBemoje(): {
|
|
7
|
+
configs: {
|
|
8
|
+
readonly recommended: {
|
|
9
|
+
plugins: {
|
|
10
|
+
readonly 'eslint-plugin-bemoje': any;
|
|
11
|
+
};
|
|
12
|
+
rules: {
|
|
13
|
+
'no-blank-line-between-comment-and-declaration': _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
|
|
14
|
+
description: string;
|
|
15
|
+
recommended?: boolean;
|
|
16
|
+
requiresTypeChecking?: boolean;
|
|
17
|
+
}, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
meta: {
|
|
24
|
+
name: string;
|
|
25
|
+
version: string;
|
|
26
|
+
};
|
|
27
|
+
rules: {
|
|
28
|
+
'no-blank-line-between-comment-and-declaration': _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
|
|
29
|
+
description: string;
|
|
30
|
+
recommended?: boolean;
|
|
31
|
+
requiresTypeChecking?: boolean;
|
|
32
|
+
}, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
33
|
+
name: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { eslintPluginBemoje };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ESLintUtils, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
var createRule = ESLintUtils.RuleCreator((name) => {
|
|
6
|
+
return `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/rules/noBlankLineBetweenCommentAndDeclaration.ts
|
|
10
|
+
var noBlankLineBetweenCommentAndDeclaration = createRule({
|
|
11
|
+
name: "no-blank-line-between-comment-and-declaration",
|
|
12
|
+
meta: {
|
|
13
|
+
fixable: "whitespace",
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Consistant whitespace ",
|
|
16
|
+
recommended: true
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
"no-blank-line-between-comment-and-declaration": "Block comments for a declaration must not leave blank lines between them."
|
|
20
|
+
},
|
|
21
|
+
type: "problem",
|
|
22
|
+
schema: []
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [
|
|
25
|
+
"error"
|
|
26
|
+
],
|
|
27
|
+
create(context) {
|
|
28
|
+
return {
|
|
29
|
+
Program(program) {
|
|
30
|
+
program.comments?.forEach((comment) => {
|
|
31
|
+
if (comment.type !== AST_TOKEN_TYPES.Block) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const nextToken = context.sourceCode.getTokenAfter(comment);
|
|
38
|
+
if (!nextToken) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const actualNextTokenStartLine = nextToken.loc.start.line;
|
|
42
|
+
const expectedTokenStartLine = comment.loc.end.line + 1;
|
|
43
|
+
if (!(actualNextTokenStartLine > expectedTokenStartLine)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const lineBeforeNextToken = context.sourceCode.lines[nextToken.loc.start.line - 1 - 1];
|
|
47
|
+
const hasLineCommentBetween = lineBeforeNextToken.trim().startsWith("//");
|
|
48
|
+
if (hasLineCommentBetween) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
return context.report({
|
|
52
|
+
node: program,
|
|
53
|
+
messageId: "no-blank-line-between-comment-and-declaration",
|
|
54
|
+
fix(fixer) {
|
|
55
|
+
const start = comment.range[0];
|
|
56
|
+
const end = nextToken.range[1];
|
|
57
|
+
const rangeCode = context.sourceCode.text.slice(start, end);
|
|
58
|
+
const rangeCodeFixed = rangeCode.replaceAll(/\*\/\n\n+/gi, "*/\n");
|
|
59
|
+
return fixer.replaceTextRange([
|
|
60
|
+
start,
|
|
61
|
+
end
|
|
62
|
+
], rangeCodeFixed);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// src/lib/eslintPluginBemoje.ts
|
|
72
|
+
function eslintPluginBemoje() {
|
|
73
|
+
const rules = {
|
|
74
|
+
"no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration
|
|
75
|
+
};
|
|
76
|
+
const plugins = {
|
|
77
|
+
get "eslint-plugin-bemoje"() {
|
|
78
|
+
return eslintPluginBemoje();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
configs: {
|
|
83
|
+
get recommended() {
|
|
84
|
+
return {
|
|
85
|
+
plugins,
|
|
86
|
+
rules
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
meta: {
|
|
91
|
+
name: "eslint-plugin-bemoje",
|
|
92
|
+
version: "1.0.1"
|
|
93
|
+
},
|
|
94
|
+
rules
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
__name(eslintPluginBemoje, "eslintPluginBemoje");
|
|
98
|
+
|
|
99
|
+
export { eslintPluginBemoje };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@typescript-eslint/utils');
|
|
4
|
+
|
|
5
|
+
// src/rules/noBlankLineBetweenCommentAndDeclaration.ts
|
|
6
|
+
var createRule = utils.ESLintUtils.RuleCreator((name) => {
|
|
7
|
+
return `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/rules/noBlankLineBetweenCommentAndDeclaration.ts
|
|
11
|
+
var noBlankLineBetweenCommentAndDeclaration = createRule({
|
|
12
|
+
name: "no-blank-line-between-comment-and-declaration",
|
|
13
|
+
meta: {
|
|
14
|
+
fixable: "whitespace",
|
|
15
|
+
docs: {
|
|
16
|
+
description: "Consistant whitespace ",
|
|
17
|
+
recommended: true
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
"no-blank-line-between-comment-and-declaration": "Block comments for a declaration must not leave blank lines between them."
|
|
21
|
+
},
|
|
22
|
+
type: "problem",
|
|
23
|
+
schema: []
|
|
24
|
+
},
|
|
25
|
+
defaultOptions: [
|
|
26
|
+
"error"
|
|
27
|
+
],
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
Program(program) {
|
|
31
|
+
program.comments?.forEach((comment) => {
|
|
32
|
+
if (comment.type !== utils.AST_TOKEN_TYPES.Block) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const nextToken = context.sourceCode.getTokenAfter(comment);
|
|
39
|
+
if (!nextToken) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const actualNextTokenStartLine = nextToken.loc.start.line;
|
|
43
|
+
const expectedTokenStartLine = comment.loc.end.line + 1;
|
|
44
|
+
if (!(actualNextTokenStartLine > expectedTokenStartLine)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const lineBeforeNextToken = context.sourceCode.lines[nextToken.loc.start.line - 1 - 1];
|
|
48
|
+
const hasLineCommentBetween = lineBeforeNextToken.trim().startsWith("//");
|
|
49
|
+
if (hasLineCommentBetween) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return context.report({
|
|
53
|
+
node: program,
|
|
54
|
+
messageId: "no-blank-line-between-comment-and-declaration",
|
|
55
|
+
fix(fixer) {
|
|
56
|
+
const start = comment.range[0];
|
|
57
|
+
const end = nextToken.range[1];
|
|
58
|
+
const rangeCode = context.sourceCode.text.slice(start, end);
|
|
59
|
+
const rangeCodeFixed = rangeCode.replaceAll(/\*\/\n\n+/gi, "*/\n");
|
|
60
|
+
return fixer.replaceTextRange([
|
|
61
|
+
start,
|
|
62
|
+
end
|
|
63
|
+
], rangeCodeFixed);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
exports.noBlankLineBetweenCommentAndDeclaration = noBlankLineBetweenCommentAndDeclaration;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enforce no blank lines between block comments and the next declaration.
|
|
5
|
+
*/
|
|
6
|
+
declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
|
|
7
|
+
description: string;
|
|
8
|
+
recommended?: boolean;
|
|
9
|
+
requiresTypeChecking?: boolean;
|
|
10
|
+
}, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { noBlankLineBetweenCommentAndDeclaration };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enforce no blank lines between block comments and the next declaration.
|
|
5
|
+
*/
|
|
6
|
+
declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
|
|
7
|
+
description: string;
|
|
8
|
+
recommended?: boolean;
|
|
9
|
+
requiresTypeChecking?: boolean;
|
|
10
|
+
}, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { noBlankLineBetweenCommentAndDeclaration };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ESLintUtils, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
// src/rules/noBlankLineBetweenCommentAndDeclaration.ts
|
|
4
|
+
var createRule = ESLintUtils.RuleCreator((name) => {
|
|
5
|
+
return `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`;
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/rules/noBlankLineBetweenCommentAndDeclaration.ts
|
|
9
|
+
var noBlankLineBetweenCommentAndDeclaration = createRule({
|
|
10
|
+
name: "no-blank-line-between-comment-and-declaration",
|
|
11
|
+
meta: {
|
|
12
|
+
fixable: "whitespace",
|
|
13
|
+
docs: {
|
|
14
|
+
description: "Consistant whitespace ",
|
|
15
|
+
recommended: true
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
"no-blank-line-between-comment-and-declaration": "Block comments for a declaration must not leave blank lines between them."
|
|
19
|
+
},
|
|
20
|
+
type: "problem",
|
|
21
|
+
schema: []
|
|
22
|
+
},
|
|
23
|
+
defaultOptions: [
|
|
24
|
+
"error"
|
|
25
|
+
],
|
|
26
|
+
create(context) {
|
|
27
|
+
return {
|
|
28
|
+
Program(program) {
|
|
29
|
+
program.comments?.forEach((comment) => {
|
|
30
|
+
if (comment.type !== AST_TOKEN_TYPES.Block) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const nextToken = context.sourceCode.getTokenAfter(comment);
|
|
37
|
+
if (!nextToken) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const actualNextTokenStartLine = nextToken.loc.start.line;
|
|
41
|
+
const expectedTokenStartLine = comment.loc.end.line + 1;
|
|
42
|
+
if (!(actualNextTokenStartLine > expectedTokenStartLine)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const lineBeforeNextToken = context.sourceCode.lines[nextToken.loc.start.line - 1 - 1];
|
|
46
|
+
const hasLineCommentBetween = lineBeforeNextToken.trim().startsWith("//");
|
|
47
|
+
if (hasLineCommentBetween) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return context.report({
|
|
51
|
+
node: program,
|
|
52
|
+
messageId: "no-blank-line-between-comment-and-declaration",
|
|
53
|
+
fix(fixer) {
|
|
54
|
+
const start = comment.range[0];
|
|
55
|
+
const end = nextToken.range[1];
|
|
56
|
+
const rangeCode = context.sourceCode.text.slice(start, end);
|
|
57
|
+
const rangeCodeFixed = rangeCode.replaceAll(/\*\/\n\n+/gi, "*/\n");
|
|
58
|
+
return fixer.replaceTextRange([
|
|
59
|
+
start,
|
|
60
|
+
end
|
|
61
|
+
], rangeCodeFixed);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export { noBlankLineBetweenCommentAndDeclaration };
|
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/eslint",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Custom ESLint plugin and rule utilities for consistent code style in TypeScript projects.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"sideEffects": false,
|
|
7
5
|
"keywords": [
|
|
8
6
|
"eslint",
|
|
9
7
|
"eslint-plugin",
|
|
@@ -13,33 +11,86 @@
|
|
|
13
11
|
"utilities",
|
|
14
12
|
"typescript"
|
|
15
13
|
],
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./index.d.ts",
|
|
19
|
-
"import": "./index.mjs",
|
|
20
|
-
"default": "./index.mjs"
|
|
21
|
-
},
|
|
22
|
-
"./*": {
|
|
23
|
-
"types": "./index.d.ts",
|
|
24
|
-
"import": "./index.mjs",
|
|
25
|
-
"default": "./index.mjs"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
14
|
"dependencies": {
|
|
29
15
|
"@typescript-eslint/utils": "^8.56.1"
|
|
30
16
|
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"sideEffects": false,
|
|
31
19
|
"publishConfig": {
|
|
32
20
|
"access": "public"
|
|
33
21
|
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
22
|
+
"main": "./lib/index.cjs",
|
|
23
|
+
"module": "./lib/index.js",
|
|
24
|
+
"types": "./lib/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./lib/index.d.ts",
|
|
29
|
+
"default": "./lib/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./lib/index.d.cts",
|
|
33
|
+
"default": "./lib/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./lib/createRule": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./lib/lib/createRule.d.ts",
|
|
39
|
+
"default": "./lib/lib/createRule.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./lib/lib/createRule.d.cts",
|
|
43
|
+
"default": "./lib/lib/createRule.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./lib/eslintPluginBemoje": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./lib/lib/eslintPluginBemoje.d.ts",
|
|
49
|
+
"default": "./lib/lib/eslintPluginBemoje.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./lib/lib/eslintPluginBemoje.d.cts",
|
|
53
|
+
"default": "./lib/lib/eslintPluginBemoje.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./rules/noBlankLineBetweenCommentAndDeclaration": {
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./lib/rules/noBlankLineBetweenCommentAndDeclaration.d.ts",
|
|
59
|
+
"default": "./lib/rules/noBlankLineBetweenCommentAndDeclaration.js"
|
|
60
|
+
},
|
|
61
|
+
"require": {
|
|
62
|
+
"types": "./lib/rules/noBlankLineBetweenCommentAndDeclaration.d.cts",
|
|
63
|
+
"default": "./lib/rules/noBlankLineBetweenCommentAndDeclaration.cjs"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
39
66
|
},
|
|
67
|
+
"files": [
|
|
68
|
+
"./lib/index.js",
|
|
69
|
+
"./lib/index.d.ts",
|
|
70
|
+
"./lib/index.cjs",
|
|
71
|
+
"./lib/index.d.cts",
|
|
72
|
+
"./lib/lib/createRule.js",
|
|
73
|
+
"./lib/lib/createRule.d.ts",
|
|
74
|
+
"./lib/lib/createRule.cjs",
|
|
75
|
+
"./lib/lib/createRule.d.cts",
|
|
76
|
+
"./lib/lib/eslintPluginBemoje.js",
|
|
77
|
+
"./lib/lib/eslintPluginBemoje.d.ts",
|
|
78
|
+
"./lib/lib/eslintPluginBemoje.cjs",
|
|
79
|
+
"./lib/lib/eslintPluginBemoje.d.cts",
|
|
80
|
+
"./lib/rules/noBlankLineBetweenCommentAndDeclaration.js",
|
|
81
|
+
"./lib/rules/noBlankLineBetweenCommentAndDeclaration.d.ts",
|
|
82
|
+
"./lib/rules/noBlankLineBetweenCommentAndDeclaration.cjs",
|
|
83
|
+
"./lib/rules/noBlankLineBetweenCommentAndDeclaration.d.cts"
|
|
84
|
+
],
|
|
40
85
|
"repository": {
|
|
41
86
|
"type": "git",
|
|
42
87
|
"url": "git+https://github.com/bemoje/mono.git",
|
|
43
88
|
"directory": "libs/eslint"
|
|
44
|
-
}
|
|
89
|
+
},
|
|
90
|
+
"author": {
|
|
91
|
+
"name": "Benjamin Møller Jensen",
|
|
92
|
+
"email": "bemoje@bemoje.net",
|
|
93
|
+
"url": "https://github.com/bemoje/"
|
|
94
|
+
},
|
|
95
|
+
"license": "MIT"
|
|
45
96
|
}
|
|
File without changes
|