@brighterly/lib-fe-codestyle 0.1.2 → 0.2.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
@@ -65,6 +65,13 @@ exported as data.
65
65
  | `_C6` | warn | a raw `font-family` / `font-size` / `font-weight` declaration instead of the app's typography source |
66
66
  | `_C7` | warn | `<script>` attribute order differing from the app's canonical (`setup lang` vs `lang setup`) |
67
67
 
68
+ Level discipline: `error` is reserved for crash-class rules (`_R*` — a visitor-facing
69
+ throw or silent production breakage); `warn` is for conventions and style choices
70
+ (`_C*`). A consumer's `levels` ceiling on an `_R*` rule is NOT the tool for an existing
71
+ backlog — fix the call sites or allowlist the reviewed exceptions with reasons.
72
+ Underscore-prefixed SCSS partials (`_extends.scss`, `_colors-*.scss`, …) are declaration
73
+ files by convention in every Brighterly app and are exempt from `_C3`/`_C6` wholesale.
74
+
68
75
  `_R*` were ported from land-app, where each was a production scar (as `R1`, `R7`, `R18`,
69
76
  `R28` — renumbered sequentially when the prefix landed, pre-publish, while no released
70
77
  version pinned the old tokens). `_C*` are conventions with
@@ -93,6 +100,7 @@ A shared rule must not hardcode a consuming app's paths. Each app declares them
93
100
  // invariants/config.mts
94
101
  export const settings = {
95
102
  safeStorageModule: 'safeLocalStorage from @helpers/safe-local-storage',
103
+ safeStorageFile: 'app/utils/helpers/safe-local-storage.ts', // _R1 auto-exempts the wrapper itself
96
104
  safeJsonParse: 'parseStoredJson() from @helpers/safe-local-storage',
97
105
  scssTokensFile: 'app/assets/scss/_colors.scss',
98
106
  uiKitRoot: 'app/components/UI',
@@ -88,13 +88,13 @@ const scssColourTokens = {
88
88
  fix: 'use a token variable from the palette file; if the colour is genuinely new, add it to the palette first',
89
89
  scope: ['app/assets/scss/**/*.scss', 'app/components/**/*.vue'],
90
90
  check: ({ file, code, settings }) => {
91
- // The palette files DEFINE the literals — they are the one place they belong.
92
- const palette = setting({ settings }, 'scssTokensFile', 'app/assets/scss/_colors.scss');
93
- const paletteFiles = [palette, 'app/assets/scss/_vars.scss', 'app/assets/scss/_colors.scss'];
94
- if (paletteFiles.some(p => file === p))
91
+ // Underscore-prefixed partials are DECLARATION files by SCSS convention in every
92
+ // Brighterly app (_colors, _vars, _extends, _mixins, brand variants, …) — they are
93
+ // where the literals belong, so the whole class is exempt (decided 2026-09-24).
94
+ if (/\/_[^/]*\.scss$/.test(file))
95
95
  return [];
96
- // `[\w-]*` covers brand variants like _colors-smartestminds.scss (cs-app is multi-brand).
97
- if (/\/_(?:colors|vars|palette|tokens)[\w-]*\.scss$/.test(file))
96
+ const palette = setting({ settings }, 'scssTokensFile', 'app/assets/scss/_colors.scss');
97
+ if (file === palette)
98
98
  return [];
99
99
  return eachLine(code, (line, n) => {
100
100
  // `rgba($token, .5)` is correct usage — only a NUMERIC first argument is a literal.
@@ -174,9 +174,10 @@ const typographySource = {
174
174
  scope: ['app/assets/scss/**/*.scss', 'app/components/**/*.vue'],
175
175
  check: ({ file, code, settings }) => {
176
176
  const source = setting({ settings }, 'typographySource', 'the app\'s shared typography mixins or text components');
177
- // The files that DEFINE the typography are the one place raw declarations belong.
178
- // `[\w-]*` covers brand variants like _vars-smartestminds.scss (cs-app is multi-brand).
179
- if (/\/_?(?:mixins|vars|fonts|typography|colors)[\w-]*\.scss$/.test(file))
177
+ // The files that DEFINE the typography are the one place raw declarations belong:
178
+ // every underscore-prefixed partial (declaration files by SCSS convention in the
179
+ // Brighterly apps, decided 2026-09-24), plus non-underscore fonts/typography files.
180
+ if (/\/(?:_[^/]*|fonts|typography)\.scss$/.test(file))
180
181
  return [];
181
182
  // @font-face declares a face, not a usage — _R4 polices those blocks.
182
183
  const stripped = code.replace(/@font-face\s*\{[^}]*\}/g, m => m.replace(/[^\n]/g, ' '));
@@ -20,6 +20,10 @@ const bareStorage = {
20
20
  scope: ['app/**/*.{ts,vue}'],
21
21
  exclude: ['app/tests/**', 'app/test/**'],
22
22
  check: ({ file, code, settings }) => {
23
+ // The wrapper itself is the one place bare access belongs — settings-driven, so no
24
+ // consumer has to allowlist its own wrapper.
25
+ if (settings?.safeStorageFile && file === settings.safeStorageFile)
26
+ return [];
23
27
  const wrapper = setting({ settings }, 'safeStorageModule', 'the safe storage helper');
24
28
  return eachLine(code, (line, n) => {
25
29
  if (/\b(?:window\s*\.\s*)?(?:local|session)Storage\s*[.[]/.test(line)) {
@@ -58,6 +58,8 @@ export interface ReportedFinding extends Finding {
58
58
  export interface SharedRuleSettings {
59
59
  /** `_R1`/`_R3` fix messages: how this app names its safe storage wrapper, e.g. 'safeLocalStorage from @helpers/safe-local-storage'. */
60
60
  safeStorageModule?: string;
61
+ /** `_R1`: repo-relative path of the wrapper FILE itself — the one place bare storage access belongs, auto-exempted so no app has to allowlist its own wrapper. E.g. 'app/utils/helpers/safe-local-storage.ts'. */
62
+ safeStorageFile?: string;
61
63
  /** `_R3` fix message: the guarded parse helper, e.g. 'parseStoredJson() from @helpers/safe-local-storage'. */
62
64
  safeJsonParse?: string;
63
65
  /** `_C3`: the palette file that legitimately DEFINES colour literals, e.g. 'app/assets/scss/_colors.scss'. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brighterly/lib-fe-codestyle",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Shared invariant-validator engine, rule pack and ESLint config for Brighterly Nuxt frontend apps",
@@ -61,4 +61,4 @@
61
61
  "typescript-eslint": "^8.70.1",
62
62
  "vitest": "^4.1.10"
63
63
  }
64
- }
64
+ }