@bemoje/eslint 2.1.1 → 2.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/README.md CHANGED
@@ -101,3 +101,5 @@ export function add(a: number, b: number) {
101
101
  ```
102
102
 
103
103
  Single-line block comments and line comments between the block comment and the declaration are ignored.
104
+
105
+ A file's header is left alone: the block comment that nothing comes before (a shebang line aside) is about the file, so it keeps the blank line after it.
package/lib/index.cjs CHANGED
@@ -5,6 +5,8 @@ var utils = require('@typescript-eslint/utils');
5
5
  var __defProp = Object.defineProperty;
6
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
7
  var createRule = utils.ESLintUtils.RuleCreator((name) => `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`);
8
+
9
+ // src/rules/noBlankLineBetweenCommentAndDeclaration.ts
8
10
  var noBlankLineBetweenCommentAndDeclaration = createRule({
9
11
  name: "no-blank-line-between-comment-and-declaration",
10
12
  meta: {
@@ -32,6 +34,12 @@ var noBlankLineBetweenCommentAndDeclaration = createRule({
32
34
  if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
33
35
  return;
34
36
  }
37
+ const before = context.sourceCode.getTokenBefore(comment, {
38
+ includeComments: true
39
+ });
40
+ if (!before || before.type === "Shebang") {
41
+ return;
42
+ }
35
43
  const nextToken = context.sourceCode.getTokenAfter(comment, {
36
44
  includeComments: true
37
45
  });
@@ -131,6 +139,28 @@ var bemojePlugin = {
131
139
  }
132
140
  };
133
141
 
142
+ // src/configs/enforceNoBlankLineBetweenCommentAndDeclaration.ts
143
+ var enforceNoBlankLineBetweenCommentAndDeclaration = {
144
+ name: "@bemoje/eslint/no-blank-line-between-comment-and-declaration",
145
+ plugins: {
146
+ bemoje: bemojePlugin
147
+ },
148
+ rules: {
149
+ "bemoje/no-blank-line-between-comment-and-declaration": "error"
150
+ }
151
+ };
152
+
153
+ // src/configs/enforceSplitImports.ts
154
+ var enforceSplitImports = {
155
+ name: "@bemoje/eslint/split-imports",
156
+ plugins: {
157
+ bemoje: bemojePlugin
158
+ },
159
+ rules: {
160
+ "bemoje/split-imports": "error"
161
+ }
162
+ };
163
+
134
164
  // src/lib/eslintPluginBemoje.ts
135
165
  function eslintPluginBemoje() {
136
166
  const rules = bemojePlugin.rules;
@@ -153,39 +183,18 @@ function eslintPluginBemoje() {
153
183
  },
154
184
  meta: {
155
185
  name: "eslint-plugin-bemoje",
156
- version: "2.1.1"
186
+ version: "2.1.2"
157
187
  },
158
188
  rules
159
189
  };
160
190
  }
161
191
  __name(eslintPluginBemoje, "eslintPluginBemoje");
162
192
 
163
- // src/configs/enforceNoBlankLineBetweenCommentAndDeclaration.ts
164
- var enforceNoBlankLineBetweenCommentAndDeclaration = {
165
- name: "@bemoje/eslint/no-blank-line-between-comment-and-declaration",
166
- plugins: {
167
- bemoje: bemojePlugin
168
- },
169
- rules: {
170
- "bemoje/no-blank-line-between-comment-and-declaration": "error"
171
- }
172
- };
173
-
174
- // src/configs/enforceSplitImports.ts
175
- var enforceSplitImports = {
176
- name: "@bemoje/eslint/split-imports",
177
- plugins: {
178
- bemoje: bemojePlugin
179
- },
180
- rules: {
181
- "bemoje/split-imports": "error"
182
- }
183
- };
184
-
185
193
  exports.bemojePlugin = bemojePlugin;
186
194
  exports.createRule = createRule;
187
195
  exports.enforceNoBlankLineBetweenCommentAndDeclaration = enforceNoBlankLineBetweenCommentAndDeclaration;
188
196
  exports.enforceSplitImports = enforceSplitImports;
189
197
  exports.eslintPluginBemoje = eslintPluginBemoje;
190
198
  exports.noBlankLineBetweenCommentAndDeclaration = noBlankLineBetweenCommentAndDeclaration;
199
+ exports.ruleForEslint = ruleForEslint;
191
200
  exports.splitImports = splitImports;
package/lib/index.d.cts CHANGED
@@ -1,21 +1,6 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
2
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
3
3
 
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
4
  /**
20
5
  * The types this package's plugin and config entries are offered under. They say what ESLint's own config type
21
6
  * (`Linter.Config`) asks for and nothing more, so an entry goes into a typed config with no cast. A rule keeps its
@@ -42,6 +27,50 @@ interface ConfigForEslint {
42
27
  plugins: Record<string, PluginForEslint>;
43
28
  rules: Record<string, 'error'>;
44
29
  }
30
+ /**
31
+ * A rule written with typescript-eslint, as the type ESLint's config asks for. The one cast of this package: the two
32
+ * rule types differ only in the node types their listeners name (a listener of typescript-eslint takes its own node
33
+ * types, and in 8.57 its catch-all listener takes `never`), never in what runs.
34
+ */
35
+ declare const ruleForEslint: (rule: {
36
+ meta?: object;
37
+ create: (context: never) => object;
38
+ }) => RuleForEslint;
39
+
40
+ /**
41
+ * A ready-made ESLint flat config entry that turns the rule `no-blank-line-between-comment-and-declaration` on as an
42
+ * error: a block comment over several lines has no blank line between it and the code right after it. Put it in the
43
+ * list a config file exports, with no plugin to register and no rule name to type.
44
+ */
45
+ declare const enforceNoBlankLineBetweenCommentAndDeclaration: ConfigForEslint;
46
+
47
+ /**
48
+ * A ready-made ESLint flat config entry that turns the rule `split-imports` on as an error: one import declaration
49
+ * per imported name. Put it in the list a config file exports, with no plugin to register and no rule name to type.
50
+ */
51
+ declare const enforceSplitImports: ConfigForEslint;
52
+
53
+ /**
54
+ * The one plugin object that every ready-made config entry of this package registers, under the name `bemoje`.
55
+ * ESLint accepts the same plugin name in several config entries only when it is the same object each time, so the
56
+ * entries share this one. A rule's full name is `bemoje/<rule>`, for an `eslint-disable` comment.
57
+ */
58
+ declare const bemojePlugin: PluginForEslint;
59
+
60
+ /**
61
+ * Helper to create an ESLint rule with a consistent format.
62
+ */
63
+ declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, {
64
+ description: string;
65
+ recommended?: boolean;
66
+ requiresTypeChecking?: boolean;
67
+ }>>) => ESLintUtils.RuleModule<MessageIds, Options, {
68
+ description: string;
69
+ recommended?: boolean;
70
+ requiresTypeChecking?: boolean;
71
+ }, ESLintUtils.RuleListener> & {
72
+ name: string;
73
+ };
45
74
 
46
75
  /** What `eslintPluginBemoje()` returns: the plugin, and a config that registers it and turns every rule on. */
47
76
  interface EslintPluginBemoje extends PluginForEslint {
@@ -60,7 +89,8 @@ interface EslintPluginBemoje extends PluginForEslint {
60
89
  declare function eslintPluginBemoje(): EslintPluginBemoje;
61
90
 
62
91
  /**
63
- * Enforce no blank lines between block comments and the next declaration.
92
+ * Enforce no blank lines between block comments and the next declaration. A file's header, the comment that nothing
93
+ * comes before, is left alone.
64
94
  */
65
95
  declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
66
96
  description: string;
@@ -81,24 +111,4 @@ declare const splitImports: _typescript_eslint_utils_ts_eslint.RuleModule<"split
81
111
  name: string;
82
112
  };
83
113
 
84
- /**
85
- * The one plugin object that every ready-made config entry of this package registers, under the name `bemoje`.
86
- * ESLint accepts the same plugin name in several config entries only when it is the same object each time, so the
87
- * entries share this one. A rule's full name is `bemoje/<rule>`, for an `eslint-disable` comment.
88
- */
89
- declare const bemojePlugin: PluginForEslint;
90
-
91
- /**
92
- * A ready-made ESLint flat config entry that turns the rule `no-blank-line-between-comment-and-declaration` on as an
93
- * error: a block comment over several lines has no blank line between it and the code right after it. Put it in the
94
- * list a config file exports, with no plugin to register and no rule name to type.
95
- */
96
- declare const enforceNoBlankLineBetweenCommentAndDeclaration: ConfigForEslint;
97
-
98
- /**
99
- * A ready-made ESLint flat config entry that turns the rule `split-imports` on as an error: one import declaration
100
- * per imported name. Put it in the list a config file exports, with no plugin to register and no rule name to type.
101
- */
102
- declare const enforceSplitImports: ConfigForEslint;
103
-
104
- export { bemojePlugin, createRule, enforceNoBlankLineBetweenCommentAndDeclaration, enforceSplitImports, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, splitImports };
114
+ export { type ConfigForEslint, type EslintPluginBemoje, type PluginForEslint, type RuleForEslint, bemojePlugin, createRule, enforceNoBlankLineBetweenCommentAndDeclaration, enforceSplitImports, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, ruleForEslint, splitImports };
package/lib/index.d.ts CHANGED
@@ -1,21 +1,6 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
2
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
3
3
 
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
4
  /**
20
5
  * The types this package's plugin and config entries are offered under. They say what ESLint's own config type
21
6
  * (`Linter.Config`) asks for and nothing more, so an entry goes into a typed config with no cast. A rule keeps its
@@ -42,6 +27,50 @@ interface ConfigForEslint {
42
27
  plugins: Record<string, PluginForEslint>;
43
28
  rules: Record<string, 'error'>;
44
29
  }
30
+ /**
31
+ * A rule written with typescript-eslint, as the type ESLint's config asks for. The one cast of this package: the two
32
+ * rule types differ only in the node types their listeners name (a listener of typescript-eslint takes its own node
33
+ * types, and in 8.57 its catch-all listener takes `never`), never in what runs.
34
+ */
35
+ declare const ruleForEslint: (rule: {
36
+ meta?: object;
37
+ create: (context: never) => object;
38
+ }) => RuleForEslint;
39
+
40
+ /**
41
+ * A ready-made ESLint flat config entry that turns the rule `no-blank-line-between-comment-and-declaration` on as an
42
+ * error: a block comment over several lines has no blank line between it and the code right after it. Put it in the
43
+ * list a config file exports, with no plugin to register and no rule name to type.
44
+ */
45
+ declare const enforceNoBlankLineBetweenCommentAndDeclaration: ConfigForEslint;
46
+
47
+ /**
48
+ * A ready-made ESLint flat config entry that turns the rule `split-imports` on as an error: one import declaration
49
+ * per imported name. Put it in the list a config file exports, with no plugin to register and no rule name to type.
50
+ */
51
+ declare const enforceSplitImports: ConfigForEslint;
52
+
53
+ /**
54
+ * The one plugin object that every ready-made config entry of this package registers, under the name `bemoje`.
55
+ * ESLint accepts the same plugin name in several config entries only when it is the same object each time, so the
56
+ * entries share this one. A rule's full name is `bemoje/<rule>`, for an `eslint-disable` comment.
57
+ */
58
+ declare const bemojePlugin: PluginForEslint;
59
+
60
+ /**
61
+ * Helper to create an ESLint rule with a consistent format.
62
+ */
63
+ declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, {
64
+ description: string;
65
+ recommended?: boolean;
66
+ requiresTypeChecking?: boolean;
67
+ }>>) => ESLintUtils.RuleModule<MessageIds, Options, {
68
+ description: string;
69
+ recommended?: boolean;
70
+ requiresTypeChecking?: boolean;
71
+ }, ESLintUtils.RuleListener> & {
72
+ name: string;
73
+ };
45
74
 
46
75
  /** What `eslintPluginBemoje()` returns: the plugin, and a config that registers it and turns every rule on. */
47
76
  interface EslintPluginBemoje extends PluginForEslint {
@@ -60,7 +89,8 @@ interface EslintPluginBemoje extends PluginForEslint {
60
89
  declare function eslintPluginBemoje(): EslintPluginBemoje;
61
90
 
62
91
  /**
63
- * Enforce no blank lines between block comments and the next declaration.
92
+ * Enforce no blank lines between block comments and the next declaration. A file's header, the comment that nothing
93
+ * comes before, is left alone.
64
94
  */
65
95
  declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_ts_eslint.RuleModule<"no-blank-line-between-comment-and-declaration", [string], {
66
96
  description: string;
@@ -81,24 +111,4 @@ declare const splitImports: _typescript_eslint_utils_ts_eslint.RuleModule<"split
81
111
  name: string;
82
112
  };
83
113
 
84
- /**
85
- * The one plugin object that every ready-made config entry of this package registers, under the name `bemoje`.
86
- * ESLint accepts the same plugin name in several config entries only when it is the same object each time, so the
87
- * entries share this one. A rule's full name is `bemoje/<rule>`, for an `eslint-disable` comment.
88
- */
89
- declare const bemojePlugin: PluginForEslint;
90
-
91
- /**
92
- * A ready-made ESLint flat config entry that turns the rule `no-blank-line-between-comment-and-declaration` on as an
93
- * error: a block comment over several lines has no blank line between it and the code right after it. Put it in the
94
- * list a config file exports, with no plugin to register and no rule name to type.
95
- */
96
- declare const enforceNoBlankLineBetweenCommentAndDeclaration: ConfigForEslint;
97
-
98
- /**
99
- * A ready-made ESLint flat config entry that turns the rule `split-imports` on as an error: one import declaration
100
- * per imported name. Put it in the list a config file exports, with no plugin to register and no rule name to type.
101
- */
102
- declare const enforceSplitImports: ConfigForEslint;
103
-
104
- export { bemojePlugin, createRule, enforceNoBlankLineBetweenCommentAndDeclaration, enforceSplitImports, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, splitImports };
114
+ export { type ConfigForEslint, type EslintPluginBemoje, type PluginForEslint, type RuleForEslint, bemojePlugin, createRule, enforceNoBlankLineBetweenCommentAndDeclaration, enforceSplitImports, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, ruleForEslint, splitImports };
package/lib/index.js CHANGED
@@ -3,6 +3,8 @@ import { ESLintUtils, AST_TOKEN_TYPES, AST_NODE_TYPES } from '@typescript-eslint
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
5
  var createRule = ESLintUtils.RuleCreator((name) => `https://github.com/bemoje/mono/blob/dev/libs/eslint/README.md#${name}`);
6
+
7
+ // src/rules/noBlankLineBetweenCommentAndDeclaration.ts
6
8
  var noBlankLineBetweenCommentAndDeclaration = createRule({
7
9
  name: "no-blank-line-between-comment-and-declaration",
8
10
  meta: {
@@ -30,6 +32,12 @@ var noBlankLineBetweenCommentAndDeclaration = createRule({
30
32
  if (Math.abs(comment.loc.start.line - comment.loc.end.line) < 2) {
31
33
  return;
32
34
  }
35
+ const before = context.sourceCode.getTokenBefore(comment, {
36
+ includeComments: true
37
+ });
38
+ if (!before || before.type === "Shebang") {
39
+ return;
40
+ }
33
41
  const nextToken = context.sourceCode.getTokenAfter(comment, {
34
42
  includeComments: true
35
43
  });
@@ -129,6 +137,28 @@ var bemojePlugin = {
129
137
  }
130
138
  };
131
139
 
140
+ // src/configs/enforceNoBlankLineBetweenCommentAndDeclaration.ts
141
+ var enforceNoBlankLineBetweenCommentAndDeclaration = {
142
+ name: "@bemoje/eslint/no-blank-line-between-comment-and-declaration",
143
+ plugins: {
144
+ bemoje: bemojePlugin
145
+ },
146
+ rules: {
147
+ "bemoje/no-blank-line-between-comment-and-declaration": "error"
148
+ }
149
+ };
150
+
151
+ // src/configs/enforceSplitImports.ts
152
+ var enforceSplitImports = {
153
+ name: "@bemoje/eslint/split-imports",
154
+ plugins: {
155
+ bemoje: bemojePlugin
156
+ },
157
+ rules: {
158
+ "bemoje/split-imports": "error"
159
+ }
160
+ };
161
+
132
162
  // src/lib/eslintPluginBemoje.ts
133
163
  function eslintPluginBemoje() {
134
164
  const rules = bemojePlugin.rules;
@@ -151,33 +181,11 @@ function eslintPluginBemoje() {
151
181
  },
152
182
  meta: {
153
183
  name: "eslint-plugin-bemoje",
154
- version: "2.1.1"
184
+ version: "2.1.2"
155
185
  },
156
186
  rules
157
187
  };
158
188
  }
159
189
  __name(eslintPluginBemoje, "eslintPluginBemoje");
160
190
 
161
- // src/configs/enforceNoBlankLineBetweenCommentAndDeclaration.ts
162
- var enforceNoBlankLineBetweenCommentAndDeclaration = {
163
- name: "@bemoje/eslint/no-blank-line-between-comment-and-declaration",
164
- plugins: {
165
- bemoje: bemojePlugin
166
- },
167
- rules: {
168
- "bemoje/no-blank-line-between-comment-and-declaration": "error"
169
- }
170
- };
171
-
172
- // src/configs/enforceSplitImports.ts
173
- var enforceSplitImports = {
174
- name: "@bemoje/eslint/split-imports",
175
- plugins: {
176
- bemoje: bemojePlugin
177
- },
178
- rules: {
179
- "bemoje/split-imports": "error"
180
- }
181
- };
182
-
183
- export { bemojePlugin, createRule, enforceNoBlankLineBetweenCommentAndDeclaration, enforceSplitImports, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, splitImports };
191
+ export { bemojePlugin, createRule, enforceNoBlankLineBetweenCommentAndDeclaration, enforceSplitImports, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, ruleForEslint, splitImports };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/eslint",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Custom ESLint plugin and rule utilities for consistent code style in TypeScript projects.",
5
5
  "type": "module",
6
6
  "sideEffects": false,