flatlint 1.97.0 → 1.98.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
+ 2025.02.03, v1.98.0
2
+
3
+ feature:
4
+ - 2a067ca flatlint: startLine: add
5
+
6
+ 2025.02.03, v1.97.1
7
+
8
+ fix:
9
+ - 88fc720 flatlint: add-missing-comma: const
10
+
1
11
  2025.02.03, v1.97.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -321,6 +321,7 @@ When you want to use custom plugins:
321
321
  import {lint} from 'flatlint';
322
322
 
323
323
  const [code] = lint(`a && b = c`, {
324
+ startLine: 1,
324
325
  plugins: [
325
326
  ['wrap-assignment-in-parens', {
326
327
  report: () => `Wrap the assignment in parentheses after '&&'`,
package/lib/flatlint.js CHANGED
@@ -4,18 +4,25 @@ import {run} from '#runner';
4
4
  import {print} from '#printer';
5
5
 
6
6
  export function lint(source, overrides = {}) {
7
- const {fix = true, plugins: pluginNames = []} = overrides;
7
+ const {
8
+ startLine = 1,
9
+ fix = true,
10
+ plugins: pluginNames = [],
11
+ } = overrides;
12
+
8
13
  const plugins = loadPlugins({
9
14
  pluginNames,
10
15
  });
11
16
 
12
17
  const tokens = parse(source);
13
18
 
14
- const places = run(tokens, {
19
+ const rawPlaces = run(tokens, {
15
20
  plugins,
16
21
  fix,
17
22
  });
18
23
 
24
+ const places = rawPlaces.map(addStartLine(startLine));
25
+
19
26
  if (!fix)
20
27
  return [source, places];
21
28
 
@@ -24,3 +31,15 @@ export function lint(source, overrides = {}) {
24
31
  places,
25
32
  ];
26
33
  }
34
+
35
+ const addStartLine = (startLine) => (a) => {
36
+ const {line, column} = a.position;
37
+
38
+ return {
39
+ ...a,
40
+ position: {
41
+ column,
42
+ line: startLine + line - 1,
43
+ },
44
+ };
45
+ };
@@ -2,12 +2,16 @@ import {
2
2
  colon,
3
3
  isKeyword,
4
4
  quote,
5
+ assign,
5
6
  } from '#types';
6
7
 
7
8
  export const report = () => 'Add missing comma';
8
9
 
9
10
  export const match = () => ({
10
11
  '"__a"': (vars, path) => {
12
+ if (path.isPrevPunctuator(assign))
13
+ return false;
14
+
11
15
  return path.isNextIdentifier();
12
16
  },
13
17
  '__a': ({__a}, path) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.97.0",
3
+ "version": "1.98.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",