flatlint 1.11.0 → 1.12.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/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2024.12.31, v1.12.0
2
+
3
+ feature:
4
+ - dedb945 flatlint: add-missing-quote: improve
5
+
1
6
  2024.12.31, v1.11.0
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -28,6 +28,15 @@ npm i flatlint
28
28
 
29
29
  </details>
30
30
 
31
+ <details><summary>Convert <code>from</code> to <code>require</code></summary>
32
+
33
+ ```diff
34
+ -const a = from 'a';
35
+ +const a = require('a');
36
+ ```
37
+
38
+ </details>
39
+
31
40
  <details><summary>add missing round braces in if statement</summary>
32
41
 
33
42
  ```diff
@@ -1,10 +1,6 @@
1
- export function report() {
2
- return 'Add missing quote';
3
- }
1
+ export const report = () => 'Add missing quote';
4
2
 
5
- export function replace() {
6
- return {
7
- 'const __a = "__b': 'const __a = "__b"',
8
- '__a("__b)': '__a("__b")',
9
- };
10
- }
3
+ export const replace = () => ({
4
+ 'const __a = "__b;': 'const __a = "__b";',
5
+ '__a("__b)': '__a("__b")',
6
+ });
@@ -0,0 +1,5 @@
1
+ export const report = () => `Use 'require' instead of 'from'`;
2
+
3
+ export const replace = () => ({
4
+ '= from "__a"': '= require("__a")',
5
+ });
@@ -1,11 +1,7 @@
1
- export function report() {
2
- return 'Remove useless round brace';
3
- }
1
+ export const report = () => 'Remove useless round brace';
4
2
 
5
- export function replace() {
6
- return {
7
- 'const __a = __b)': 'const __a = __b',
8
- 'const __a = "__b")': 'const __a = "__b"',
9
- 'from "__b")': 'from "__b"',
10
- };
11
- }
3
+ export const replace = () => ({
4
+ 'const __a = __b)': 'const __a = __b',
5
+ 'const __a = "__b")': 'const __a = "__b"',
6
+ 'from "__b")': 'from "__b"',
7
+ });
package/lib/plugins.js CHANGED
@@ -3,13 +3,17 @@ import * as addMissingRoundBraces from './plugins/add-missing-round-braces/index
3
3
  import * as addMissingSquireBrace from './plugins/add-missing-square-brace/index.js';
4
4
  import * as addMissingQuote from './plugins/add-missing-quote/index.js';
5
5
  import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/index.js';
6
+ import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
6
7
  import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
8
+ import * as addConstToExport from './plugins/add-const-to-export/index.js';
7
9
 
8
10
  export const plugins = [
9
11
  ['wrap-assignment-in-parens', wrapAssignmentInParens],
10
12
  ['add-missing-round-braces', addMissingRoundBraces],
11
13
  ['add-missing-squire-brace', addMissingSquireBrace],
12
14
  ['add-missing-quote', addMissingQuote],
15
+ ['add-const-to-export', addConstToExport],
13
16
  ['convert-comma-to-semicolon', convertCommaToSemicolon],
17
+ ['convert-from-to-require', convertFromToRequire],
14
18
  ['remove-useless-round-brace', removeUselessRoundBrace],
15
19
  ];
@@ -1,14 +1,19 @@
1
1
  import {replace} from './replacer.js';
2
2
 
3
- export const run = (tokens, {fix, plugins}) => {
3
+ export const run = (tokens, {fix, fixCount = 10, plugins}) => {
4
4
  const places = [];
5
5
 
6
- for (const {rule, plugin} of plugins) {
7
- places.push(...replace(tokens, {
8
- fix,
9
- rule,
10
- plugin,
11
- }));
6
+ while (--fixCount) {
7
+ for (const {rule, plugin} of plugins) {
8
+ places.push(...replace(tokens, {
9
+ fix,
10
+ rule,
11
+ plugin,
12
+ }));
13
+
14
+ if (places.length)
15
+ return [places];
16
+ }
12
17
  }
13
18
 
14
19
  return [places];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",