@inthedark/dxlint 0.1.1 → 0.1.2

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
@@ -1,6 +1,6 @@
1
1
  # dxlint
2
2
 
3
- A fast linter and fixer for TypeScript, JavaScript, Rust and more. It ships ports of 400+ ESLint, typescript-eslint and ESLint Stylistic rules, the type-aware ones included, and every rule is written in a small language, `.dx`, that you can read, change or extend.
3
+ let you and your agents own your linter
4
4
 
5
5
  ```dx
6
6
  import .ts
@@ -19,20 +19,20 @@ warn: Promises must be awaited, end with a call to .catch, end with a call to .t
19
19
  | ^^^^^^^^^^^^^^^^^^^^^^
20
20
  ```
21
21
 
22
- ## Why
22
+ ## another linter? ugh...
23
23
 
24
- - **Fast.** On a 2,000-file TypeScript codebase, on one core, a full run takes under half as long as ESLint, a cached run a fifth, in about a third of the memory.
25
- - **Your ESLint rules.** 99.4% of ESLint's and typescript-eslint's own rule test cases give the same result. Type-aware rules read your `tsconfig.json` without running TypeScript.
26
- - **A cache you can trust.** `.dxcache` records everything a file's result depended on, other files included, so an edit re-checks exactly the files it affects.
27
- - **Rules are code you own.** Built-in rules are `.dx` files: override one, write your own in a few lines, or describe a whole new language.
24
+ - **it's over 200× faster than eslint+typescript-eslint.** because apples to apples requires eslint *without* its caching enabled, and dxlint's cache is intrinsic. (even without that, it's also twice as fast and significantly less memory hungry)
25
+ - **and it has almost perfect eslint parity.** 99.4% of eslint's and typescript-eslint's test cases give the same result. type-aware rules read your `tsconfig.json` *without running typescript*
26
+ - **everything is overrideable, you own it all.** built-in rules are `.dx` files: override them, tweak them, write your own, or describe a whole new language
27
+ - **plus a high quality vscode extension too!** extremely fast, with diagnostics, with a proper `.dx` lsp
28
28
 
29
- ## Getting started
29
+ ## getting started
30
30
 
31
31
  ```sh
32
32
  npm install --save-dev @inthedark/dxlint
33
33
  ```
34
34
 
35
- Put a `.dx` at your project root:
35
+ put a `.dx` at your project root:
36
36
 
37
37
  ```dx
38
38
  import .ts
@@ -48,13 +48,15 @@ ignore "dist" "src/generated/**"
48
48
  | `dxlint rules` | list every rule with its options |
49
49
  | `dxlint describe <name>` | explain a rule, option or anything else in the config |
50
50
 
51
- Exit code 1 means errors were found, 2 means the config is broken. Add `.dxcache` to `.gitignore`.
51
+ exit code 1 means errors were found, 2 means the config is broken.&nbsp;
52
52
 
53
- Next: [docs/basic.md](docs/basic.md) and [the rule list](docs/rules/README.md).
53
+ don't forget to add `.dxcache` to `.gitignore`!!!
54
54
 
55
- ## The language
55
+ for more on the basics: [docs/basic.md](docs/basic.md) and [the rule list](docs/rules/README.md).
56
56
 
57
- A rule is a few lines of `.dx`: where to look, when it is wrong, and optionally the fix.
57
+ ## the language
58
+
59
+ a rule is a few lines of `.dx`: where to look, when it is wrong, and optionally the fix
58
60
 
59
61
  ```dx
60
62
  import .ts
@@ -66,13 +68,9 @@ in ts_call.callee rule no-alert-calls error "use the notification service instea
66
68
 
67
69
  [docs/advanced.md](docs/advanced.md) covers the whole language, from rules over the built-in syntax trees to defining your own languages. [docs/ts.md](docs/ts.md) covers what the TypeScript library understands: scopes, modules, types and narrowing.
68
70
 
69
- ## Editors
70
-
71
- `dxlint lsp` is a language server: diagnostics as you type, quick fixes, fix-all, and for `.dx` files hover, go to definition, references, completion and an outline. The VS Code extension is in [editors/vscode](editors/vscode).
72
-
73
- ## Performance
71
+ ## performance
74
72
 
75
- One core (`--jobs 1`, both pinned to the same core, wall time, measured in one session), wayward (2,094 TypeScript files, its full ESLint config ported, type-aware rules included):
73
+ one core (`--jobs 1`, both pinned to the same core, wall time, measured in one session), on a project with 2,094 .ts files, its complex custom eslint config ported, type-aware rules included:
76
74
 
77
75
  | | ESLint | dxlint |
78
76
  | --- | --- | --- |
@@ -80,6 +78,6 @@ One core (`--jobs 1`, both pinned to the same core, wall time, measured in one s
80
78
  | cached run, nothing changed | 4.4 s | 0.8 s |
81
79
  | peak memory (working set) | 2.0 GB | 0.7 GB |
82
80
 
83
- Note: This isn't a fair comparison because [eslint --cache doesn't work with typescript-eslint](https://typescript-eslint.io/troubleshooting/faqs/eslint/?utm_source=chatgpt.com#can-i-use-eslints---cache-with-typescript-eslint).
81
+ and remember: this isn't a fair comparison because [eslint --cache doesn't work with typescript-eslint](https://typescript-eslint.io/troubleshooting/faqs/eslint/?utm_source=chatgpt.com#can-i-use-eslints---cache-with-typescript-eslint)!&nbsp;
84
82
 
85
- By default dxlint uses every core.
83
+ also note that by default dxlint uses every core, and is significantly better at that than eslint+typescript-eslint due to no reliance on typescript itself
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inthedark/dxlint",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Fast linter and fixer for TypeScript, JavaScript, Rust and more, with ESLint-compatible rules written in .dx",
5
5
  "license": "MIT",
6
6
  "repository": {
package/rules/bugs.dx ADDED
@@ -0,0 +1,49 @@
1
+ # rules:bugs: code that is wrong: it throws, never runs, or cannot do what it
2
+ # says. On as errors. Part of rules:recommended; no rule is in two rulesets.
3
+
4
+ rule es-await-thenable* error
5
+ rule es-constructor-super error
6
+ rule es-for-direction error
7
+ rule es-getter-return error
8
+ rule es-no-array-delete error
9
+ rule es-no-async-promise-executor error
10
+ rule es-no-base-to-string error
11
+ rule es-no-class-assign error
12
+ rule es-no-compare-neg-zero error
13
+ rule es-no-const-assign error
14
+ rule es-no-constant-binary-expression error
15
+ rule es-no-dupe-args error
16
+ rule es-no-dupe-class-members error
17
+ rule es-no-dupe-else-if error
18
+ rule es-no-dupe-keys error
19
+ rule es-no-duplicate-case error
20
+ rule es-no-duplicate-enum-values error
21
+ rule es-no-empty-character-class error
22
+ rule es-no-ex-assign error
23
+ rule es-no-floating-promises error
24
+ rule es-no-for-in-array error
25
+ rule es-no-func-assign error
26
+ rule es-no-import-assign error
27
+ rule es-no-invalid-regexp error
28
+ rule es-no-loss-of-precision error
29
+ rule es-no-misleading-character-class* error
30
+ rule es-no-misused-promises error
31
+ rule es-no-new-native-nonconstructor error
32
+ rule es-no-non-null-asserted-optional-chain error
33
+ rule es-no-obj-calls error
34
+ rule es-no-redeclare error
35
+ rule es-no-self-assign error
36
+ rule es-no-setter-return error
37
+ rule es-no-sparse-arrays error
38
+ rule es-no-this-before-super error
39
+ rule es-no-unassigned-vars error
40
+ rule es-no-undef error
41
+ rule es-no-unexpected-multiline* error
42
+ rule es-no-unreachable error
43
+ rule es-no-unsafe-declaration-merging error
44
+ rule es-no-unsafe-finally* error
45
+ rule es-no-unsafe-negation error
46
+ rule es-no-unsafe-optional-chaining* error
47
+ rule es-unbound-method error
48
+ rule es-use-isnan error
49
+ rule es-valid-typeof error
@@ -1,5 +1,5 @@
1
1
  # rules:es-no-semi: semicolon-free JavaScript and TypeScript, on top of
2
- # rules:format. Statements end without `;`; a line that would continue the
2
+ # rules:formatting. Statements end without `;`; a line that would continue the
3
3
  # previous statement (`(`, `[`, a template) starts with its guard: `;[1].map(f)`.
4
4
 
5
5
  rule es-semi {
@@ -1,10 +1,10 @@
1
- # rules:format: layout and spacing, as eslint's and @stylistic's defaults
2
- # lay code out (and topiary's for Rust). Turns on every such rule of the
3
- # imported languages; rules whose port cannot follow the upstream default
4
- # yet are left out (comma-dangle, object-curly-spacing, arrow-parens,
1
+ # rules:formatting: layout and spacing, as eslint's and @stylistic's defaults
2
+ # lay code out (and topiary's for Rust). On as warnings; not part of
3
+ # rules:recommended. Rules whose port cannot follow the upstream default yet
4
+ # are left out (comma-dangle, object-curly-spacing, arrow-parens,
5
5
  # dot-location, quote-props, operator-linebreak, one-var,
6
- # generator-star-spacing, lines-between-class-members,
7
- # padding-line-between-statements).
6
+ # generator-star-spacing, lines-between-class-members, padded-blocks,
7
+ # padding-line-between-statements). rules:es-no-semi drops semicolons on top.
8
8
 
9
9
  rule es-array-bracket-spacing
10
10
  rule es-arrow-spacing*
@@ -16,7 +16,6 @@ rule es-check-alignment*
16
16
  rule es-comma-spacing*
17
17
  rule es-comma-style
18
18
  rule es-computed-property-spacing
19
- rule shared-eol-last
20
19
  rule es-key-spacing
21
20
  rule es-keyword-spacing*
22
21
  rule es-member-delimiter-style* {
@@ -28,8 +27,6 @@ rule es-no-mixed-operators*
28
27
  rule es-no-multi-spaces
29
28
  rule es-no-multiple-empty-lines
30
29
  rule es-no-whitespace-before-property
31
- rule es-padded-blocks:always-top
32
- rule es-padded-blocks:always-bottom
33
30
  rule es-quotes* {
34
31
  set style "double"
35
32
  }
@@ -45,5 +42,6 @@ rule es-template-curly-spacing
45
42
  rule es-template-tag-spacing
46
43
  rule es-type-annotation-spacing
47
44
  rule es-yield-star-spacing
45
+ rule shared-eol-last
48
46
 
49
47
  rule rs-*
@@ -1,51 +1,6 @@
1
- # rules:recommended: the rules eslint and typescript-eslint recommend
2
- # without type information, as far as dxlint has them.
1
+ # rules:recommended: dxlint's recommendation: definite bugs as errors, likely
2
+ # mistakes and type-safety leaks as warnings. Exactly these three rulesets.
3
3
 
4
- rule es-constructor-super
5
- rule es-for-direction
6
- rule es-no-async-promise-executor
7
- rule es-no-compare-neg-zero
8
- rule es-no-cond-assign
9
- rule es-no-constant-condition*
10
- rule es-no-control-regex
11
- rule es-no-debugger
12
- rule es-no-delete-var
13
- rule es-no-dupe-else-if
14
- rule es-no-duplicate-case
15
- rule es-no-empty-character-class
16
- rule es-no-empty-pattern*
17
- rule es-no-empty-static-block
18
- rule es-no-ex-assign
19
- rule es-no-extra-boolean-cast*
20
- rule es-no-fallthrough
21
- rule es-no-global-assign
22
- rule es-no-invalid-regexp
23
- rule es-no-irregular-whitespace
24
- rule es-no-loss-of-precision
25
- rule es-no-misleading-character-class*
26
- rule es-no-misused-new*
27
- rule es-no-nonoctal-decimal-escape
28
- rule es-no-octal
29
- rule es-no-regex-spaces*
30
- rule es-no-require-imports
31
- rule es-no-self-assign
32
- rule es-no-shadow-restricted-names
33
- rule es-no-sparse-arrays
34
- rule es-no-unexpected-multiline*
35
- rule es-no-unsafe-finally*
36
- rule es-no-unsafe-function-type
37
- rule es-no-unsafe-optional-chaining*
38
- rule es-no-unused-expressions
39
- rule es-no-unused-labels
40
- rule es-no-unused-private-class-members
41
- rule es-no-unused-vars*
42
- rule es-no-useless-assignment
43
- rule es-no-useless-backreference*
44
- rule es-no-useless-catch*
45
- rule es-no-useless-escape*
46
- rule es-no-wrapper-object-types
47
- rule es-prefer-namespace-keyword
48
- rule es-require-yield
49
- rule es-triple-slash-reference
50
- rule es-use-isnan
51
- rule es-valid-typeof
4
+ import rules:bugs
5
+ import rules:suspicious
6
+ import rules:type-safety
@@ -1,9 +1,9 @@
1
- # rules:conventions: one consistent way to write things. Turns on every such
2
- # rule of the imported languages, at its defaults.
1
+ # rules:style: one consistent, modern way to write things. On as warnings;
2
+ # not part of rules:recommended. No rule is in two rulesets.
3
3
 
4
4
  rule es-adjacent-overload-signatures
5
5
  rule es-array-type*
6
- rule es-ban-tslint-comment
6
+ rule es-ban-linter-comment
7
7
  rule es-class-literal-property-style
8
8
  rule es-consistent-generic-constructors
9
9
  rule es-consistent-indexed-object-style*
@@ -14,21 +14,35 @@ rule es-eqeqeq
14
14
  rule es-explicit-function-return-type*
15
15
  rule es-explicit-member-accessibility*
16
16
  rule es-explicit-module-boundary-types*
17
+ rule es-no-array-constructor
17
18
  rule es-no-confusing-non-null-assertion*
18
19
  rule es-no-console
20
+ rule es-no-duplicate-type-constituents
19
21
  rule es-no-extraneous-class
20
22
  rule es-no-inferrable-types*
23
+ rule es-no-namespace
24
+ rule es-no-this-alias
21
25
  rule es-no-unassigned-import
22
26
  rule es-no-undef-init
27
+ rule es-no-unnecessary-boolean-literal-compare
28
+ rule es-no-unnecessary-template-expression
29
+ rule es-no-unnecessary-type-arguments
30
+ rule es-no-unnecessary-type-constraint
23
31
  rule es-no-useless-constructor
24
32
  rule es-no-var
25
33
  rule es-no-var-requires
34
+ rule es-prefer-as-const
26
35
  rule es-prefer-const
36
+ rule es-prefer-find*
27
37
  rule es-prefer-function-type
38
+ rule es-prefer-includes
28
39
  rule es-prefer-namespace-keyword
29
40
  rule es-prefer-object-spread
41
+ rule es-prefer-optional-chain
42
+ rule es-prefer-readonly*
30
43
  rule es-prefer-rest-params
31
44
  rule es-prefer-spread
45
+ rule es-prefer-string-starts-ends-with*
32
46
  rule es-prefer-template
33
47
  rule es-radix
34
48
  rule es-triple-slash-reference
@@ -1,31 +1,52 @@
1
- # rules:suspicious: code that is likely a mistake, or does nothing. Turns on
2
- # every such rule of the imported languages, at its defaults.
1
+ # rules:suspicious: likely a mistake, or code that does nothing. On as
2
+ # warnings. Part of rules:recommended; no rule is in two rulesets.
3
3
 
4
4
  rule es-no-caller
5
+ rule es-no-case-declarations
6
+ rule es-no-cond-assign
7
+ rule es-no-constant-condition*
8
+ rule es-no-control-regex
9
+ rule es-no-debugger
5
10
  rule es-no-delete-var
11
+ rule es-no-deprecated
12
+ rule es-no-empty
6
13
  rule es-no-empty-interface
14
+ rule es-no-empty-pattern*
7
15
  rule es-no-empty-static-block
8
16
  rule es-no-eval*
9
17
  rule es-no-extra-bind
10
18
  rule es-no-extra-boolean-cast*
19
+ rule es-no-extra-non-null-assertion
20
+ rule es-no-fallthrough
11
21
  rule es-no-global-assign
22
+ rule es-no-implied-eval
23
+ rule es-no-irregular-whitespace
12
24
  rule es-no-misused-new*
13
25
  rule es-no-new-func
14
26
  rule es-no-new-wrappers
15
27
  rule es-no-nonoctal-decimal-escape
16
28
  rule es-no-octal
29
+ rule es-no-prototype-builtins
30
+ rule es-no-redundant-type-constituents
17
31
  rule es-no-regex-spaces*
18
32
  rule es-no-require-imports
19
33
  rule es-no-sequences
20
34
  rule es-no-shadow-restricted-names
21
35
  rule es-no-template-curly-in-string
22
36
  rule es-no-throw-literal
23
- rule es-no-unsafe-function-type
37
+ rule es-no-unnecessary-type-assertion
24
38
  rule es-no-unused-expressions
25
39
  rule es-no-unused-imports
26
40
  rule es-no-unused-labels
41
+ rule es-no-unused-private-class-members
42
+ rule es-no-unused-vars*
43
+ rule es-no-useless-assignment
44
+ rule es-no-useless-backreference*
27
45
  rule es-no-useless-catch*
28
46
  rule es-no-useless-escape*
29
47
  rule es-no-with
30
- rule es-no-wrapper-object-types
48
+ rule es-only-throw-error
49
+ rule es-prefer-promise-reject-errors
50
+ rule es-preserve-caught-error
51
+ rule es-require-await
31
52
  rule es-require-yield
@@ -0,0 +1,18 @@
1
+ # rules:type-safety: code that switches type checking off or lets `any` and
2
+ # loose types leak. On as warnings. Part of rules:recommended; no rule is in
3
+ # two rulesets.
4
+
5
+ rule es-ban-ts-comment
6
+ rule es-no-empty-object-type
7
+ rule es-no-explicit-any
8
+ rule es-no-unsafe-argument
9
+ rule es-no-unsafe-assignment
10
+ rule es-no-unsafe-call
11
+ rule es-no-unsafe-enum-comparison
12
+ rule es-no-unsafe-function-type
13
+ rule es-no-unsafe-member-access
14
+ rule es-no-unsafe-return
15
+ rule es-no-unsafe-unary-minus
16
+ rule es-no-wrapper-object-types
17
+ rule es-restrict-plus-operands*
18
+ rule es-restrict-template-expressions
@@ -3,7 +3,7 @@
3
3
  define {
4
4
 
5
5
  # ---- comments --------------------------------------------------------------------
6
- fn tslint_comment_edit(source, n) = {
6
+ fn linter_comment_edit(source, n) = {
7
7
  value line_start: position(n.offset).js_line_start
8
8
  value prefix: byte_slice(source, line_start, n.offset)
9
9
  value tail: n.after
@@ -24,12 +24,20 @@ fn tslint_comment_edit(source, n) = {
24
24
  text: if re_test(prefix, /\S$/) && re_test(tail, /^\S/) && !re_test(tail, /^[;,)}\]]/) then " " else ""
25
25
  }
26
26
  }
27
- in ts_comment rule es-ban-tslint-comment {
27
+ # Patterns read the whole comment, `//` or `/* */` included: ESLint takes its
28
+ # config comments (`/* eslint ... */`, `/* global x */`) from block comments only.
29
+ in ts_comment rule es-ban-linter-comment {
30
+ option formats { name: string; pattern: regex }[] = [
31
+ { name: "tslint", pattern: /^(?:\/\/|\/\*)\s*tslint:(?:enable|disable)(?:-(?:line|next-line))?(?::|\s|\*\/|$)/ },
32
+ { name: "eslint", pattern: /^(?:\/\/|\/\*)\s*eslint-(?:disable|enable)(?:-(?:line|next-line))?(?:\s|\*\/|$)/ },
33
+ { name: "eslint", pattern: /^\/\*\s*(?:eslint|eslint-env|globals?|exported)(?:\s|\*\/)/ }
34
+ ] "linter comments to report: a name for the message and a pattern over the whole comment"
35
+ let format first(filter(formats, format => re_test(text, format.pattern)))
36
+ when format != null
28
37
  let content re_replace(text, /^\/\/|^\/\*|\*\/$/, "")
29
38
  let normalised re_replace(content, /^\s+|\s+$/, "")
30
- when re_test(content, /^\s*tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/)
31
- let edit tslint_comment_edit(source, node)
32
- warn "tslint comment detected: \"{if node is ts_line_comment then '// ' normalised else '/* ' normalised ' */'}\""
39
+ let edit linter_comment_edit(source, node)
40
+ warn "{format.name} comment detected: \"{if node is ts_line_comment then '// ' normalised else '/* ' normalised ' */'}\""
33
41
  fix at edit if edit != null as edit.text
34
42
  }
35
43
 
@@ -1,33 +0,0 @@
1
- # rules:correctness: code that is almost certainly wrong. Turns on every
2
- # such rule of the imported languages, at its defaults; rules of languages
3
- # not imported are skipped. `rule name off` after the import takes one back.
4
-
5
- rule es-constructor-super
6
- rule es-for-direction
7
- rule es-no-async-promise-executor
8
- rule es-no-compare-neg-zero
9
- rule es-no-cond-assign
10
- rule es-no-constant-condition*
11
- rule es-no-control-regex
12
- rule es-no-debugger
13
- rule es-no-dupe-else-if
14
- rule es-no-duplicate-case
15
- rule es-no-empty-character-class
16
- rule es-no-empty-pattern*
17
- rule es-no-ex-assign
18
- rule es-no-fallthrough
19
- rule es-no-invalid-regexp
20
- rule es-no-irregular-whitespace
21
- rule es-no-loss-of-precision
22
- rule es-no-misleading-character-class*
23
- rule es-no-self-assign
24
- rule es-no-sparse-arrays
25
- rule es-no-unexpected-multiline*
26
- rule es-no-unsafe-finally*
27
- rule es-no-unsafe-optional-chaining*
28
- rule es-no-unused-private-class-members
29
- rule es-no-unused-vars*
30
- rule es-no-useless-assignment
31
- rule es-no-useless-backreference*
32
- rule es-use-isnan
33
- rule es-valid-typeof
package/rules/types.dx DELETED
@@ -1,21 +0,0 @@
1
- # rules:types: rules that read declared types (dxlint's own type evaluator:
2
- # no TypeScript needed). Turns on every such rule of the imported languages,
3
- # at its defaults.
4
-
5
- rule es-await-thenable*
6
- rule es-no-deprecated
7
- rule es-no-floating-promises
8
- rule es-no-for-in-array
9
- rule es-no-misused-promises
10
- rule es-no-unnecessary-boolean-literal-compare
11
- rule es-no-unnecessary-template-expression
12
- rule es-no-unnecessary-type-arguments
13
- rule es-no-unsafe-unary-minus
14
- rule es-unbound-method
15
- rule es-prefer-find*
16
- rule es-prefer-includes
17
- rule es-prefer-optional-chain
18
- rule es-prefer-readonly*
19
- rule es-prefer-string-starts-ends-with*
20
- rule es-restrict-plus-operands*
21
- rule es-restrict-template-expressions