flatlint 1.4.0 → 1.5.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,13 @@
1
+ 2024.12.29, v1.5.0
2
+
3
+ feature:
4
+ - 5ff09d3 flatlint: add-missing-quote: call
5
+
6
+ 2024.12.29, v1.4.1
7
+
8
+ feature:
9
+ - 1efda41 flatlint: add-missing-quote: semicolon
10
+
1
11
  2024.12.29, v1.4.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -53,6 +53,9 @@ npm i flatlint
53
53
  ```diff
54
54
  -const a = 'hello
55
55
  +const a = 'hello'
56
+
57
+ -fn('hello);
58
+ +fn('hello');
56
59
  ```
57
60
 
58
61
  </details>
@@ -5,7 +5,7 @@ import {
5
5
  isPunctuator,
6
6
  isQuote,
7
7
  isStringLiteral,
8
- } from './types.js';
8
+ } from '../types/types.js';
9
9
 
10
10
  export const compare = (source, template) => {
11
11
  const templateTokens = prepare(template);
@@ -5,5 +5,6 @@ export function report() {
5
5
  export function replace() {
6
6
  return {
7
7
  'const __a = "__b': 'const __a = "__b"',
8
+ '__a("__b)': '__a("__b")',
8
9
  };
9
10
  }
@@ -1,6 +1,6 @@
1
1
  import {compare} from '../compare/compare.js';
2
2
  import {traverse} from '../traverser/traverser.js';
3
- import {is} from '../compare/types.js';
3
+ import {is} from '../types/types.js';
4
4
  import {prepare} from '../tokenizer/index.js';
5
5
 
6
6
  const {entries} = Object;
@@ -2,7 +2,9 @@ import tokenize from 'js-tokens';
2
2
  import {
3
3
  isNewLine,
4
4
  isStringLiteral,
5
- } from '../compare/types.js';
5
+ Punctuator,
6
+ StringLiteral,
7
+ } from '#types';
6
8
 
7
9
  const isString = (a) => typeof a === 'string';
8
10
 
@@ -15,27 +17,31 @@ const closeQuotes = (tokens) => {
15
17
  if (isStringLiteral(token)) {
16
18
  const {closed, value} = token;
17
19
 
18
- const quote = {
19
- type: 'Punctuator',
20
- value: value.at(0),
21
- };
22
-
23
- const newTokens = [];
20
+ const quote = Punctuator(value.at(0));
21
+ const newTokens = [quote];
24
22
 
25
23
  if (closed) {
26
- const literal = {
27
- value: value.slice(1, -1),
28
- type: 'StringLiteral',
29
- };
24
+ const literal = StringLiteral(value.slice(1, -1));
25
+ newTokens.push(literal, quote);
26
+ } else if (value.endsWith(');')) {
27
+ const literal = StringLiteral(value.slice(1, -2));
28
+ const brace = Punctuator(')');
29
+ const semicolon = Punctuator(';');
30
30
 
31
- newTokens.push(quote, literal, quote);
32
- } else {
33
- const literal = {
34
- value: value.slice(1),
35
- type: 'StringLiteral',
36
- };
31
+ newTokens.push(literal, brace, semicolon);
32
+ } else if (value.endsWith(')')) {
33
+ const literal = StringLiteral(value.slice(1, -1));
34
+ const brace = Punctuator(')');
37
35
 
38
- newTokens.push(quote, literal);
36
+ newTokens.push(literal, brace);
37
+ } else if (value.endsWith(';')) {
38
+ const literal = StringLiteral(value.slice(1, -1));
39
+ const semicolon = Punctuator(';');
40
+
41
+ newTokens.push(literal, semicolon);
42
+ } else {
43
+ const literal = StringLiteral(value.slice(1));
44
+ newTokens.push(literal);
39
45
  }
40
46
 
41
47
  tokens.splice(i, 1, ...newTokens);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isIdentifier,
3
3
  isStringLiteral,
4
- } from '../compare/types.js';
4
+ } from '../types/types.js';
5
5
 
6
6
  const maybeCall = (fn, a) => fn?.(a);
7
7
 
@@ -8,6 +8,16 @@ export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
8
8
  export const notWhiteSpace = (a) => !isWhiteSpace(a);
9
9
  export const isPunctuator = ({type}) => type === 'Punctuator';
10
10
 
11
+ export const StringLiteral = (value) => ({
12
+ type: 'StringLiteral',
13
+ value,
14
+ });
15
+
16
+ export const Punctuator = (value) => ({
17
+ type: 'Punctuator',
18
+ value,
19
+ });
20
+
11
21
  export const is = (str, array = ALL) => {
12
22
  for (const item of array) {
13
23
  if (check(str, item))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",
@@ -11,6 +11,9 @@
11
11
  "#test": {
12
12
  "default": "./lib/test/test.js"
13
13
  },
14
+ "#types": {
15
+ "default": "./lib/types/types.js"
16
+ },
14
17
  "#flatlint": {
15
18
  "default": "./lib/flatlint.js"
16
19
  }