@ls-stack/fast-lint 0.5.0 → 0.7.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/README.md CHANGED
@@ -467,6 +467,19 @@ Comments starting with `INFO:`, `TODO:`, `DOCS:`, `FIX:`, `FIXME:`, `HACK:`, `NO
467
467
  `ISSUE:`, `TEMP:`, `TEMPORARY:`, `XXX:`, `REVIEW:`, `eslint`, `cspell:` or `spell-checker:` are allowed. The rule is
468
468
  heuristic: it can miss commented code.
469
469
 
470
+ Explanation comments required by other rules (`require-type-guard-explanation`'s `type-guard-safety:` by default) are
471
+ prose, so a line comment starting with one of `explanationPrefixes`, plus the `//` lines right below it, is never
472
+ reported.
473
+
474
+ ```ts
475
+ type Options = [
476
+ {
477
+ /** Prefixes of explanation comment blocks to skip (default: `['type-guard-safety:']`; replaces the default) */
478
+ explanationPrefixes?: string[]
479
+ },
480
+ ]
481
+ ```
482
+
470
483
  ### `react-single-export`
471
484
 
472
485
  In React component files (by default `*.tsx`), a file that exports a component (a PascalCase function, arrow,
@@ -810,9 +823,13 @@ safe and why TS inference or an alternative can't be used.
810
823
  - the comment goes right before the function or before the statement, `export`, class member or object property
811
824
  holding it; consecutive `//` lines form one block, and block/JSDoc comments count too
812
825
  - an explicit predicate TypeScript (5.5+) would infer identically is reported even with a comment, with a suggestion
813
- to remove the annotation (`inferablePredicate`); only null/undefined and `typeof` checks it is sure about are
814
- reported
826
+ to remove the annotation (`inferablePredicate`); it is conservative and only reports `===`/`!==` checks against
827
+ `null`, `undefined` and string/number literals, `typeof` checks and `instanceof` (non-generic classes), combined with
828
+ `||`/`&&`, that it is sure TypeScript infers identically
815
829
  - body-less signatures (overloads, `declare function`, interface members, function types) and `asserts x` are ignored
830
+ - `alternativeMsgs` appends a project-specific hint to the `missingExplanation` message, e.g. pointing to a schema
831
+ validator or a `filterAndMap` helper; the most specific one wins: `inArrayFind`/`inArrayFilter` for guards passed
832
+ directly to `.find()`/`.filter()`, then `unknownInput` for guards narrowing an `unknown` parameter, then `default`
816
833
 
817
834
  ```ts
818
835
  // Error: missingExplanation
@@ -840,6 +857,17 @@ type Options = [
840
857
  commentPrefix?: string
841
858
  /** Minimum characters of explanation after the prefix (default: 20) */
842
859
  minLength?: number
860
+ /** Extra hints appended to the `missingExplanation` message, the most specific one wins */
861
+ alternativeMsgs?: {
862
+ /** Every guard */
863
+ default?: string
864
+ /** Guards narrowing an `unknown` parameter (falls back to `default`) */
865
+ unknownInput?: string
866
+ /** Guards passed directly to `.find()` */
867
+ inArrayFind?: string
868
+ /** Guards passed directly to `.filter()` */
869
+ inArrayFilter?: string
870
+ }
843
871
  },
844
872
  ]
845
873
  ```
Binary file
Binary file
Binary file
Binary file
Binary file
package/lib/index.d.ts CHANGED
@@ -217,9 +217,19 @@ export type NoRestrictedCommentsOptions = {
217
217
  }[]
218
218
  }
219
219
 
220
+ export type NoCommentedOutCodeOptions = {
221
+ explanationPrefixes?: string[]
222
+ }
223
+
220
224
  export type RequireTypeGuardExplanationOptions = {
221
225
  commentPrefix?: string
222
226
  minLength?: number
227
+ alternativeMsgs?: {
228
+ default?: string
229
+ unknownInput?: string
230
+ inArrayFind?: string
231
+ inArrayFilter?: string
232
+ }
223
233
  }
224
234
 
225
235
  export type RequireUsageExplanationOptions = {
@@ -257,7 +267,7 @@ type RuleOptions = {
257
267
  'no-unnecessary-iife': Record<string, never>
258
268
  'require-description': RequireDescriptionOptions
259
269
  'no-write-only-ref': Record<string, never>
260
- 'no-commented-out-code': Record<string, never>
270
+ 'no-commented-out-code': NoCommentedOutCodeOptions
261
271
  'react-single-export': ReactSingleExportOptions
262
272
  'no-unused-optional-args': NoUnusedOptionalArgsOptions
263
273
  'no-unused-type-props-in-args': NoUnusedTypePropsInArgsOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ls-stack/fast-lint",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "license": "MIT",
5
5
  "description": "Fast type-aware lint rules for TypeScript and React, running natively on tsrs, the Rust port of the TypeScript checker",
6
6
  "type": "module",