src/check.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 38
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 14
mnd 0
bc 0
fnc 1
dl 0
loc 38
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A check.ts ➔ classNamesCheck 0 29 1
1
import { EMPTY_OBJECT } from "./consts.json"
2
import type { ClassHash } from "./main.types"
3
import type { CssModule } from "./definitions.types"
4
5
export {
6
  classNamesCheck
7
}
8
9
/**
10
 * Identical function or returning constant `EMPTY_OBJECT` for keys check of not used classes in components tree
11
 * @example
12
 * ```tsx
13
 *  // Dummies shape
14
 *  <Component classnames={classNamesCheck()} />;
15
 * ```
16
 * ---
17
 * ```tsx
18
 * import type { ClassNamesFrom } from "react-classnaming/types"
19
 * import css_module from "./some.css" // With class `.never-used {...}`
20
 *
21
 *  <Component classnames={classNamesCheck(
22
 *    css_module,
23
 *    //@ts-expect-error Property 'never-used' is missing
24
 *    {} as ClassNamesFrom<typeof Component>
25
 *  )} />;
26
 * ```
27
 */
28
 function classNamesCheck<
29
  Target extends {[K in keyof Module]: ClassHash},
30
  Module extends CssModule
31
>(
32
  source = EMPTY_OBJECT as Module,
33
  _ = EMPTY_OBJECT as Target
34
): string extends keyof Module ? Target : Module {
35
  //@ts-expect-error
36
  return source
37
}
38