@so1ve/eslint-plugin 0.69.0 → 0.70.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/dist/index.cjs CHANGED
@@ -4,9 +4,9 @@ const utils = require('@typescript-eslint/utils');
4
4
 
5
5
  const createEslintRule = utils.ESLintUtils.RuleCreator((ruleName) => ruleName);
6
6
 
7
- const RULE_NAME$3 = "import-dedupe";
7
+ const RULE_NAME$4 = "import-dedupe";
8
8
  const importDedupe = createEslintRule({
9
- name: RULE_NAME$3,
9
+ name: RULE_NAME$4,
10
10
  meta: {
11
11
  type: "problem",
12
12
  docs: {
@@ -27,7 +27,7 @@ const importDedupe = createEslintRule({
27
27
  return;
28
28
  }
29
29
  const names = /* @__PURE__ */ new Set();
30
- node.specifiers.forEach((n) => {
30
+ for (const n of node.specifiers) {
31
31
  const id = n.local.name;
32
32
  if (names.has(id)) {
33
33
  context.report({
@@ -48,15 +48,15 @@ const importDedupe = createEslintRule({
48
48
  });
49
49
  }
50
50
  names.add(id);
51
- });
51
+ }
52
52
  }
53
53
  };
54
54
  }
55
55
  });
56
56
 
57
- const RULE_NAME$2 = "no-inline-type-import";
57
+ const RULE_NAME$3 = "no-inline-type-import";
58
58
  const noInlineTypeImport = createEslintRule({
59
- name: RULE_NAME$2,
59
+ name: RULE_NAME$3,
60
60
  meta: {
61
61
  type: "layout",
62
62
  docs: {
@@ -77,7 +77,7 @@ const noInlineTypeImport = createEslintRule({
77
77
  const specifiers = node.specifiers;
78
78
  const typeSpecifiers = specifiers.filter((s) => s.type === "ImportSpecifier" && s.importKind === "type");
79
79
  const valueSpecifiers = specifiers.filter((s) => s.type === "ImportSpecifier" && s.importKind === "value");
80
- if (typeSpecifiers.length && valueSpecifiers.length) {
80
+ if (typeSpecifiers.length > 0 && valueSpecifiers.length > 0) {
81
81
  context.report({
82
82
  loc: node.loc,
83
83
  messageId: "noInlineTypeImport",
@@ -91,7 +91,7 @@ import { ${valueSpecifiersText} } from "${node.source.value}";`
91
91
  );
92
92
  }
93
93
  });
94
- } else if (typeSpecifiers.length) {
94
+ } else if (typeSpecifiers.length > 0) {
95
95
  context.report({
96
96
  loc: node.loc,
97
97
  messageId: "noInlineTypeImport",
@@ -106,9 +106,9 @@ import { ${valueSpecifiersText} } from "${node.source.value}";`
106
106
  }
107
107
  });
108
108
 
109
- const RULE_NAME$1 = "no-useless-template-string";
109
+ const RULE_NAME$2 = "no-useless-template-string";
110
110
  const noUselessTemplateString = createEslintRule({
111
- name: RULE_NAME$1,
111
+ name: RULE_NAME$2,
112
112
  meta: {
113
113
  type: "problem",
114
114
  docs: {
@@ -142,9 +142,9 @@ const noUselessTemplateString = createEslintRule({
142
142
  }
143
143
  });
144
144
 
145
- const RULE_NAME = "pad-after-last-import";
145
+ const RULE_NAME$1 = "pad-after-last-import";
146
146
  const padAfterLastImport = createEslintRule({
147
- name: RULE_NAME,
147
+ name: RULE_NAME$1,
148
148
  meta: {
149
149
  type: "problem",
150
150
  docs: {
@@ -168,7 +168,7 @@ const padAfterLastImport = createEslintRule({
168
168
  "Program:exit"() {
169
169
  if (lastImportNode) {
170
170
  const nextToken = sourceCode.getTokenAfter(lastImportNode);
171
- if (nextToken && lastImportNode.loc.end.line + 1 === nextToken.loc.start.line) {
171
+ if (nextToken && nextToken.value !== "<\/script>" && lastImportNode.loc.end.line + 1 === nextToken.loc.start.line) {
172
172
  context.report({
173
173
  node: lastImportNode,
174
174
  messageId: "padAfterLastImport",
@@ -181,11 +181,54 @@ const padAfterLastImport = createEslintRule({
181
181
  }
182
182
  });
183
183
 
184
+ const RULE_NAME = "no-beginning-newline";
185
+ const noBeginningNewline = createEslintRule({
186
+ name: RULE_NAME,
187
+ meta: {
188
+ type: "layout",
189
+ docs: {
190
+ description: "No beginning newline",
191
+ recommended: "error"
192
+ },
193
+ fixable: "whitespace",
194
+ schema: [],
195
+ messages: {
196
+ noBeginningNewline: "No beginning newline"
197
+ }
198
+ },
199
+ defaultOptions: [],
200
+ create: (context) => {
201
+ const text = context.getSourceCode().text;
202
+ return {
203
+ Program: (node) => {
204
+ const newlines = text.match(/([\n]*)/)[1];
205
+ if (newlines.length > 0) {
206
+ context.report({
207
+ node,
208
+ loc: {
209
+ start: {
210
+ line: 0,
211
+ column: 0
212
+ },
213
+ end: node.loc.start
214
+ },
215
+ messageId: "noBeginningNewline",
216
+ *fix(fixer) {
217
+ yield fixer.removeRange([0, node.range[0]]);
218
+ }
219
+ });
220
+ }
221
+ }
222
+ };
223
+ }
224
+ });
225
+
184
226
  const index = {
185
227
  rules: {
186
228
  "import-dedupe": importDedupe,
187
229
  "no-inline-type-import": noInlineTypeImport,
188
230
  "no-useless-template-string": noUselessTemplateString,
231
+ "no-beginning-newline": noBeginningNewline,
189
232
  "pad-after-last-import": padAfterLastImport
190
233
  }
191
234
  };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  "import-dedupe": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"importDedupe", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
6
6
  "no-inline-type-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
7
7
  "no-useless-template-string": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
8
+ "no-beginning-newline": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noBeginningNewline", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
8
9
  "pad-after-last-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
9
10
  };
10
11
  };
package/dist/index.mjs CHANGED
@@ -2,9 +2,9 @@ import { ESLintUtils } from '@typescript-eslint/utils';
2
2
 
3
3
  const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
4
4
 
5
- const RULE_NAME$3 = "import-dedupe";
5
+ const RULE_NAME$4 = "import-dedupe";
6
6
  const importDedupe = createEslintRule({
7
- name: RULE_NAME$3,
7
+ name: RULE_NAME$4,
8
8
  meta: {
9
9
  type: "problem",
10
10
  docs: {
@@ -25,7 +25,7 @@ const importDedupe = createEslintRule({
25
25
  return;
26
26
  }
27
27
  const names = /* @__PURE__ */ new Set();
28
- node.specifiers.forEach((n) => {
28
+ for (const n of node.specifiers) {
29
29
  const id = n.local.name;
30
30
  if (names.has(id)) {
31
31
  context.report({
@@ -46,15 +46,15 @@ const importDedupe = createEslintRule({
46
46
  });
47
47
  }
48
48
  names.add(id);
49
- });
49
+ }
50
50
  }
51
51
  };
52
52
  }
53
53
  });
54
54
 
55
- const RULE_NAME$2 = "no-inline-type-import";
55
+ const RULE_NAME$3 = "no-inline-type-import";
56
56
  const noInlineTypeImport = createEslintRule({
57
- name: RULE_NAME$2,
57
+ name: RULE_NAME$3,
58
58
  meta: {
59
59
  type: "layout",
60
60
  docs: {
@@ -75,7 +75,7 @@ const noInlineTypeImport = createEslintRule({
75
75
  const specifiers = node.specifiers;
76
76
  const typeSpecifiers = specifiers.filter((s) => s.type === "ImportSpecifier" && s.importKind === "type");
77
77
  const valueSpecifiers = specifiers.filter((s) => s.type === "ImportSpecifier" && s.importKind === "value");
78
- if (typeSpecifiers.length && valueSpecifiers.length) {
78
+ if (typeSpecifiers.length > 0 && valueSpecifiers.length > 0) {
79
79
  context.report({
80
80
  loc: node.loc,
81
81
  messageId: "noInlineTypeImport",
@@ -89,7 +89,7 @@ import { ${valueSpecifiersText} } from "${node.source.value}";`
89
89
  );
90
90
  }
91
91
  });
92
- } else if (typeSpecifiers.length) {
92
+ } else if (typeSpecifiers.length > 0) {
93
93
  context.report({
94
94
  loc: node.loc,
95
95
  messageId: "noInlineTypeImport",
@@ -104,9 +104,9 @@ import { ${valueSpecifiersText} } from "${node.source.value}";`
104
104
  }
105
105
  });
106
106
 
107
- const RULE_NAME$1 = "no-useless-template-string";
107
+ const RULE_NAME$2 = "no-useless-template-string";
108
108
  const noUselessTemplateString = createEslintRule({
109
- name: RULE_NAME$1,
109
+ name: RULE_NAME$2,
110
110
  meta: {
111
111
  type: "problem",
112
112
  docs: {
@@ -140,9 +140,9 @@ const noUselessTemplateString = createEslintRule({
140
140
  }
141
141
  });
142
142
 
143
- const RULE_NAME = "pad-after-last-import";
143
+ const RULE_NAME$1 = "pad-after-last-import";
144
144
  const padAfterLastImport = createEslintRule({
145
- name: RULE_NAME,
145
+ name: RULE_NAME$1,
146
146
  meta: {
147
147
  type: "problem",
148
148
  docs: {
@@ -166,7 +166,7 @@ const padAfterLastImport = createEslintRule({
166
166
  "Program:exit"() {
167
167
  if (lastImportNode) {
168
168
  const nextToken = sourceCode.getTokenAfter(lastImportNode);
169
- if (nextToken && lastImportNode.loc.end.line + 1 === nextToken.loc.start.line) {
169
+ if (nextToken && nextToken.value !== "<\/script>" && lastImportNode.loc.end.line + 1 === nextToken.loc.start.line) {
170
170
  context.report({
171
171
  node: lastImportNode,
172
172
  messageId: "padAfterLastImport",
@@ -179,11 +179,54 @@ const padAfterLastImport = createEslintRule({
179
179
  }
180
180
  });
181
181
 
182
+ const RULE_NAME = "no-beginning-newline";
183
+ const noBeginningNewline = createEslintRule({
184
+ name: RULE_NAME,
185
+ meta: {
186
+ type: "layout",
187
+ docs: {
188
+ description: "No beginning newline",
189
+ recommended: "error"
190
+ },
191
+ fixable: "whitespace",
192
+ schema: [],
193
+ messages: {
194
+ noBeginningNewline: "No beginning newline"
195
+ }
196
+ },
197
+ defaultOptions: [],
198
+ create: (context) => {
199
+ const text = context.getSourceCode().text;
200
+ return {
201
+ Program: (node) => {
202
+ const newlines = text.match(/([\n]*)/)[1];
203
+ if (newlines.length > 0) {
204
+ context.report({
205
+ node,
206
+ loc: {
207
+ start: {
208
+ line: 0,
209
+ column: 0
210
+ },
211
+ end: node.loc.start
212
+ },
213
+ messageId: "noBeginningNewline",
214
+ *fix(fixer) {
215
+ yield fixer.removeRange([0, node.range[0]]);
216
+ }
217
+ });
218
+ }
219
+ }
220
+ };
221
+ }
222
+ });
223
+
182
224
  const index = {
183
225
  rules: {
184
226
  "import-dedupe": importDedupe,
185
227
  "no-inline-type-import": noInlineTypeImport,
186
228
  "no-useless-template-string": noUselessTemplateString,
229
+ "no-beginning-newline": noBeginningNewline,
187
230
  "pad-after-last-import": padAfterLastImport
188
231
  }
189
232
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.69.0",
3
+ "version": "0.70.0",
4
4
  "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
5
5
  "contributors": [
6
6
  {
@@ -32,17 +32,14 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@typescript-eslint/utils": "^5.58.0",
35
- "@vue/reactivity": "^3.2.47",
36
- "eslint-define-config": "^1.18.0"
35
+ "@vue/reactivity": "^3.2.47"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@types/node": "^18.15.11",
40
- "@typescript-eslint/types": "^5.58.0",
41
- "unbuild": "^1.2.1",
42
- "vitest": "^0.30.1"
39
+ "@typescript-eslint/types": "^5.58.0"
43
40
  },
44
41
  "scripts": {
45
- "build": "rimraf dist && unbuild",
42
+ "build": "unbuild",
46
43
  "stub": "unbuild --stub",
47
44
  "test": "vitest"
48
45
  }