@bemoje/eslint 1.1.5 → 1.2.0

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
@@ -2,8 +2,17 @@
2
2
 
3
3
  Custom ESLint plugin and rule utilities for consistent code style in TypeScript projects.
4
4
 
5
- [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/)
6
- [![Module](https://img.shields.io/badge/Module-ESM-yellow)](https://nodejs.org/api/esm.html)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/) [![Module](https://img.shields.io/badge/Module-ESM-yellow)](https://nodejs.org/api/esm.html)
6
+
7
+ ## Exports
8
+
9
+ <!-- EXPORTS_START -->
10
+
11
+ - **createRule**: Helper to create an ESLint rule with a consistent format.
12
+ - **eslintPluginBemoje**: ESLint plugin for Bemoje projects.
13
+ - **noBlankLineBetweenCommentAndDeclaration**: Enforce no blank lines between block comments and the next declaration.
14
+
15
+ <!-- EXPORTS_END -->
7
16
 
8
17
  ## Installation
9
18
 
@@ -49,8 +58,7 @@ export default [{ plugins, rules }]
49
58
 
50
59
  ### no-blank-line-between-comment-and-declaration
51
60
 
52
- Enforces that there are no blank lines between a block comment (JSDoc or multi-line) and the declaration it
53
- documents. Auto-fixable.
61
+ Enforces that there are no blank lines between a block comment (JSDoc or multi-line) and the declaration it documents. Auto-fixable.
54
62
 
55
63
  **Incorrect:**
56
64
 
@@ -76,11 +84,3 @@ export function add(a: number, b: number) {
76
84
  ```
77
85
 
78
86
  Single-line block comments and line comments between the block comment and the declaration are ignored.
79
-
80
- ## API Reference
81
-
82
- | Export | Description |
83
- | ----------------------------------------- | ------------------------------------------------------------ |
84
- | `eslintPluginBemoje` | Returns the ESLint plugin object with rules and configs |
85
- | `createRule` | Helper for creating ESLint rules with consistent metadata |
86
- | `noBlankLineBetweenCommentAndDeclaration` | Rule: no blank lines between block comments and declarations |
package/lib/index.cjs CHANGED
@@ -68,10 +68,65 @@ var noBlankLineBetweenCommentAndDeclaration = createRule({
68
68
  }
69
69
  });
70
70
 
71
+ // src/rules/splitImports.ts
72
+ var splitImports = createRule({
73
+ name: "split-imports",
74
+ meta: {
75
+ docs: {
76
+ description: "Require one line per import, disallow multiple imports"
77
+ },
78
+ fixable: "code",
79
+ messages: {
80
+ "split-import": "Split multi-import into seperate import declarations."
81
+ },
82
+ type: "suggestion",
83
+ schema: []
84
+ },
85
+ create(context) {
86
+ return {
87
+ ImportDeclaration(node) {
88
+ if (node.specifiers.length > 1) {
89
+ const sourceCode = context.sourceCode;
90
+ const insideBraces = sourceCode.getText(node).match(/{([^{}]+)}/)?.[1]?.split(",").map((s) => {
91
+ return s.trim();
92
+ }).filter((s) => {
93
+ return !!s;
94
+ }) ?? [];
95
+ const maybeWrapInBraces = /* @__PURE__ */ __name((code) => {
96
+ return insideBraces.includes(code) ? `{ ${code} }` : code;
97
+ }, "maybeWrapInBraces");
98
+ const isType = /* @__PURE__ */ __name((code) => {
99
+ return node.importKind === "type" || code.startsWith("type ");
100
+ }, "isType");
101
+ const stripTypeKeyword = /* @__PURE__ */ __name((code) => {
102
+ return code.replace(/\btype\s+\b/, "").trim();
103
+ }, "stripTypeKeyword");
104
+ const importStrings = node.specifiers.map((specifier) => {
105
+ const code = sourceCode.getText(specifier).trim();
106
+ return [
107
+ isType(code) ? "import type" : "import",
108
+ maybeWrapInBraces(stripTypeKeyword(code)),
109
+ `from "${node.source.value}";`
110
+ ].join(" ");
111
+ });
112
+ context.report({
113
+ fix: /* @__PURE__ */ __name((fixer) => {
114
+ return fixer.replaceText(node, importStrings.join("\n"));
115
+ }, "fix"),
116
+ messageId: "split-import",
117
+ node
118
+ });
119
+ }
120
+ }
121
+ };
122
+ }
123
+ });
124
+
71
125
  // src/lib/eslintPluginBemoje.ts
72
126
  function eslintPluginBemoje() {
73
127
  const rules = {
74
- "no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration
128
+ "no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration,
129
+ "split-imports": splitImports
75
130
  };
76
131
  const plugins = {
77
132
  get "eslint-plugin-bemoje"() {
@@ -89,7 +144,7 @@ function eslintPluginBemoje() {
89
144
  },
90
145
  meta: {
91
146
  name: "eslint-plugin-bemoje",
92
- version: "1.0.1"
147
+ version: "1.2.0"
93
148
  },
94
149
  rules
95
150
  };
@@ -99,3 +154,4 @@ __name(eslintPluginBemoje, "eslintPluginBemoje");
99
154
  exports.createRule = createRule;
100
155
  exports.eslintPluginBemoje = eslintPluginBemoje;
101
156
  exports.noBlankLineBetweenCommentAndDeclaration = noBlankLineBetweenCommentAndDeclaration;
157
+ exports.splitImports = splitImports;
package/lib/index.d.cts CHANGED
@@ -33,6 +33,13 @@ declare function eslintPluginBemoje(): {
33
33
  }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
34
34
  name: string;
35
35
  };
36
+ 'split-imports': _typescript_eslint_utils_ts_eslint.RuleModule<"split-import", readonly unknown[], {
37
+ description: string;
38
+ recommended?: boolean;
39
+ requiresTypeChecking?: boolean;
40
+ }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
41
+ name: string;
42
+ };
36
43
  };
37
44
  };
38
45
  };
@@ -48,6 +55,13 @@ declare function eslintPluginBemoje(): {
48
55
  }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
49
56
  name: string;
50
57
  };
58
+ 'split-imports': _typescript_eslint_utils_ts_eslint.RuleModule<"split-import", readonly unknown[], {
59
+ description: string;
60
+ recommended?: boolean;
61
+ requiresTypeChecking?: boolean;
62
+ }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
63
+ name: string;
64
+ };
51
65
  };
52
66
  };
53
67
 
@@ -62,4 +76,15 @@ declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_
62
76
  name: string;
63
77
  };
64
78
 
65
- export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration };
79
+ /**
80
+ * Enforce no blank lines between block comments and the next declaration.
81
+ */
82
+ declare const splitImports: _typescript_eslint_utils_ts_eslint.RuleModule<"split-import", readonly unknown[], {
83
+ description: string;
84
+ recommended?: boolean;
85
+ requiresTypeChecking?: boolean;
86
+ }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
87
+ name: string;
88
+ };
89
+
90
+ export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, splitImports };
package/lib/index.d.ts CHANGED
@@ -33,6 +33,13 @@ declare function eslintPluginBemoje(): {
33
33
  }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
34
34
  name: string;
35
35
  };
36
+ 'split-imports': _typescript_eslint_utils_ts_eslint.RuleModule<"split-import", readonly unknown[], {
37
+ description: string;
38
+ recommended?: boolean;
39
+ requiresTypeChecking?: boolean;
40
+ }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
41
+ name: string;
42
+ };
36
43
  };
37
44
  };
38
45
  };
@@ -48,6 +55,13 @@ declare function eslintPluginBemoje(): {
48
55
  }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
49
56
  name: string;
50
57
  };
58
+ 'split-imports': _typescript_eslint_utils_ts_eslint.RuleModule<"split-import", readonly unknown[], {
59
+ description: string;
60
+ recommended?: boolean;
61
+ requiresTypeChecking?: boolean;
62
+ }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
63
+ name: string;
64
+ };
51
65
  };
52
66
  };
53
67
 
@@ -62,4 +76,15 @@ declare const noBlankLineBetweenCommentAndDeclaration: _typescript_eslint_utils_
62
76
  name: string;
63
77
  };
64
78
 
65
- export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration };
79
+ /**
80
+ * Enforce no blank lines between block comments and the next declaration.
81
+ */
82
+ declare const splitImports: _typescript_eslint_utils_ts_eslint.RuleModule<"split-import", readonly unknown[], {
83
+ description: string;
84
+ recommended?: boolean;
85
+ requiresTypeChecking?: boolean;
86
+ }, _typescript_eslint_utils_ts_eslint.RuleListener> & {
87
+ name: string;
88
+ };
89
+
90
+ export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, splitImports };
package/lib/index.js CHANGED
@@ -66,10 +66,65 @@ var noBlankLineBetweenCommentAndDeclaration = createRule({
66
66
  }
67
67
  });
68
68
 
69
+ // src/rules/splitImports.ts
70
+ var splitImports = createRule({
71
+ name: "split-imports",
72
+ meta: {
73
+ docs: {
74
+ description: "Require one line per import, disallow multiple imports"
75
+ },
76
+ fixable: "code",
77
+ messages: {
78
+ "split-import": "Split multi-import into seperate import declarations."
79
+ },
80
+ type: "suggestion",
81
+ schema: []
82
+ },
83
+ create(context) {
84
+ return {
85
+ ImportDeclaration(node) {
86
+ if (node.specifiers.length > 1) {
87
+ const sourceCode = context.sourceCode;
88
+ const insideBraces = sourceCode.getText(node).match(/{([^{}]+)}/)?.[1]?.split(",").map((s) => {
89
+ return s.trim();
90
+ }).filter((s) => {
91
+ return !!s;
92
+ }) ?? [];
93
+ const maybeWrapInBraces = /* @__PURE__ */ __name((code) => {
94
+ return insideBraces.includes(code) ? `{ ${code} }` : code;
95
+ }, "maybeWrapInBraces");
96
+ const isType = /* @__PURE__ */ __name((code) => {
97
+ return node.importKind === "type" || code.startsWith("type ");
98
+ }, "isType");
99
+ const stripTypeKeyword = /* @__PURE__ */ __name((code) => {
100
+ return code.replace(/\btype\s+\b/, "").trim();
101
+ }, "stripTypeKeyword");
102
+ const importStrings = node.specifiers.map((specifier) => {
103
+ const code = sourceCode.getText(specifier).trim();
104
+ return [
105
+ isType(code) ? "import type" : "import",
106
+ maybeWrapInBraces(stripTypeKeyword(code)),
107
+ `from "${node.source.value}";`
108
+ ].join(" ");
109
+ });
110
+ context.report({
111
+ fix: /* @__PURE__ */ __name((fixer) => {
112
+ return fixer.replaceText(node, importStrings.join("\n"));
113
+ }, "fix"),
114
+ messageId: "split-import",
115
+ node
116
+ });
117
+ }
118
+ }
119
+ };
120
+ }
121
+ });
122
+
69
123
  // src/lib/eslintPluginBemoje.ts
70
124
  function eslintPluginBemoje() {
71
125
  const rules = {
72
- "no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration
126
+ "no-blank-line-between-comment-and-declaration": noBlankLineBetweenCommentAndDeclaration,
127
+ "split-imports": splitImports
73
128
  };
74
129
  const plugins = {
75
130
  get "eslint-plugin-bemoje"() {
@@ -87,11 +142,11 @@ function eslintPluginBemoje() {
87
142
  },
88
143
  meta: {
89
144
  name: "eslint-plugin-bemoje",
90
- version: "1.0.1"
145
+ version: "1.2.0"
91
146
  },
92
147
  rules
93
148
  };
94
149
  }
95
150
  __name(eslintPluginBemoje, "eslintPluginBemoje");
96
151
 
97
- export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration };
152
+ export { createRule, eslintPluginBemoje, noBlankLineBetweenCommentAndDeclaration, splitImports };
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@bemoje/eslint",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Custom ESLint plugin and rule utilities for consistent code style in TypeScript projects.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "dependencies": {
11
+ "@typescript-eslint/utils": "^8.56.1"
12
+ },
7
13
  "keywords": [
8
14
  "eslint",
9
15
  "eslint-plugin",
@@ -33,27 +39,7 @@
33
39
  "default": "./lib/index.cjs"
34
40
  }
35
41
  },
36
- "./createRule": {
37
- "import": {
38
- "types": "./lib/index.d.ts",
39
- "default": "./lib/index.js"
40
- },
41
- "require": {
42
- "types": "./lib/index.d.cts",
43
- "default": "./lib/index.cjs"
44
- }
45
- },
46
- "./eslintPluginBemoje": {
47
- "import": {
48
- "types": "./lib/index.d.ts",
49
- "default": "./lib/index.js"
50
- },
51
- "require": {
52
- "types": "./lib/index.d.cts",
53
- "default": "./lib/index.cjs"
54
- }
55
- },
56
- "./noBlankLineBetweenCommentAndDeclaration": {
42
+ "./*": {
57
43
  "import": {
58
44
  "types": "./lib/index.d.ts",
59
45
  "default": "./lib/index.js"
@@ -64,21 +50,15 @@
64
50
  }
65
51
  }
66
52
  },
67
- "dependencies": {
68
- "@typescript-eslint/utils": "^8.56.1"
69
- },
70
- "publishConfig": {
71
- "access": "public"
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/bemoje/mono.git",
56
+ "directory": "libs/eslint"
72
57
  },
73
- "license": "MIT",
74
58
  "author": {
75
59
  "name": "Benjamin Møller Jensen",
76
60
  "email": "bemoje@bemoje.net",
77
61
  "url": "https://github.com/bemoje/"
78
62
  },
79
- "repository": {
80
- "type": "git",
81
- "url": "git+https://github.com/bemoje/mono.git",
82
- "directory": "libs/eslint"
83
- }
63
+ "license": "MIT"
84
64
  }