@brighterly/lib-fe-codestyle 0.1.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.
Files changed (36) hide show
  1. package/README.md +224 -0
  2. package/dist/invariants/ast.d.ts +72 -0
  3. package/dist/invariants/ast.js +195 -0
  4. package/dist/invariants/index.d.ts +7 -0
  5. package/dist/invariants/index.js +5 -0
  6. package/dist/invariants/rules/convention.d.ts +18 -0
  7. package/dist/invariants/rules/convention.js +226 -0
  8. package/dist/invariants/rules/fixtures.d.ts +17 -0
  9. package/dist/invariants/rules/fixtures.js +65 -0
  10. package/dist/invariants/rules/index.d.ts +55 -0
  11. package/dist/invariants/rules/index.js +53 -0
  12. package/dist/invariants/rules/linter.d.ts +10 -0
  13. package/dist/invariants/rules/linter.js +9 -0
  14. package/dist/invariants/rules/regression.d.ts +13 -0
  15. package/dist/invariants/rules/regression.js +109 -0
  16. package/dist/invariants/rules/shared.d.ts +18 -0
  17. package/dist/invariants/rules/shared.js +25 -0
  18. package/dist/invariants/run.d.ts +56 -0
  19. package/dist/invariants/run.js +553 -0
  20. package/dist/invariants/self-test.d.ts +38 -0
  21. package/dist/invariants/self-test.js +57 -0
  22. package/dist/invariants/types.d.ts +192 -0
  23. package/dist/invariants/types.js +9 -0
  24. package/dist/invariants/util.d.ts +113 -0
  25. package/dist/invariants/util.js +269 -0
  26. package/dist/validate/index.d.ts +36 -0
  27. package/dist/validate/index.js +41 -0
  28. package/eslint/index.mjs +187 -0
  29. package/eslint/rules/async-components-after-macros.mjs +63 -0
  30. package/eslint/rules/no-import-group-labels.mjs +72 -0
  31. package/eslint/rules/on-prefixed-callbacks.mjs +53 -0
  32. package/eslint/rules/optional-callback-chaining.mjs +78 -0
  33. package/eslint/rules/padding-after-macros.mjs +70 -0
  34. package/eslint/rules/ref-prefix-prop-mirrors.mjs +58 -0
  35. package/eslint/rules/require-component-name.mjs +68 -0
  36. package/package.json +64 -0
@@ -0,0 +1,68 @@
1
+ export default {
2
+ meta: {
3
+ type: 'suggestion',
4
+ fixable: 'code',
5
+ docs: {
6
+ description: 'require defineOptions({ name }) matching the file name in every component',
7
+ },
8
+ schema: [],
9
+ messages: {
10
+ missing: 'Component must declare defineOptions({ name: \'{{ name }}\' }).',
11
+ noName: 'defineOptions() must include a name property.',
12
+ },
13
+ },
14
+ create (context) {
15
+ const filename = context.filename ?? context.getFilename()
16
+ if (!filename.endsWith('.vue')) return {}
17
+
18
+ const expectedName = filename.split('/').pop().replace('.vue', '')
19
+
20
+ return {
21
+ Program (program) {
22
+ const body = program.body
23
+ if (body.length === 0) return
24
+
25
+ let defineOptionsCall = null
26
+ for (const stmt of body) {
27
+ if (
28
+ stmt.type === 'ExpressionStatement'
29
+ && stmt.expression.type === 'CallExpression'
30
+ && stmt.expression.callee.type === 'Identifier'
31
+ && stmt.expression.callee.name === 'defineOptions'
32
+ ) {
33
+ defineOptionsCall = stmt.expression
34
+ break
35
+ }
36
+ }
37
+
38
+ if (!defineOptionsCall) {
39
+ const imports = body.filter(s => s.type === 'ImportDeclaration')
40
+ const anchor = imports[imports.length - 1] ?? body[0]
41
+ const text = `defineOptions({\n name: '${expectedName}',\n})`
42
+ context.report({
43
+ node: body[0],
44
+ messageId: 'missing',
45
+ data: { name: expectedName },
46
+ fix: fixer => imports.length
47
+ ? fixer.insertTextAfter(anchor, `\n\n${text}`)
48
+ : fixer.insertTextBefore(anchor, `${text}\n\n`),
49
+ })
50
+
51
+ return
52
+ }
53
+
54
+ const arg = defineOptionsCall.arguments[0]
55
+ const hasName = arg
56
+ && arg.type === 'ObjectExpression'
57
+ && arg.properties.some(p =>
58
+ p.type === 'Property'
59
+ && !p.computed
60
+ && (p.key.name === 'name' || p.key.value === 'name'))
61
+
62
+ if (!hasName) {
63
+ context.report({ node: defineOptionsCall, messageId: 'noName' })
64
+ }
65
+ },
66
+ }
67
+ },
68
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@brighterly/lib-fe-codestyle",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "UNLICENSED",
6
+ "description": "Shared invariant-validator engine, rule pack and ESLint config for Brighterly Nuxt frontend apps",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/brighterly/lib-fe-codestyle.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "engines": {
15
+ "node": ">=22"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "eslint",
20
+ "README.md"
21
+ ],
22
+ "exports": {
23
+ "./invariants": {
24
+ "types": "./dist/invariants/index.d.ts",
25
+ "default": "./dist/invariants/index.js"
26
+ },
27
+ "./invariants/rules": {
28
+ "types": "./dist/invariants/rules/index.d.ts",
29
+ "default": "./dist/invariants/rules/index.js"
30
+ },
31
+ "./validate": {
32
+ "types": "./dist/validate/index.d.ts",
33
+ "default": "./dist/validate/index.js"
34
+ },
35
+ "./eslint": "./eslint/index.mjs"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "clean": "rm -rf dist",
40
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
41
+ "test": "vitest run",
42
+ "typecheck": "tsc -p tsconfig.json --noEmit",
43
+ "lint": "eslint",
44
+ "lint-fix": "eslint --fix",
45
+ "validate": "node validate.mjs"
46
+ },
47
+ "peerDependencies": {
48
+ "@vue/compiler-sfc": "^3.5.0",
49
+ "eslint": "^10.0.0",
50
+ "eslint-plugin-check-file": "^3.3.0",
51
+ "typescript": "^6.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@eslint/js": "^10.0.1",
55
+ "@types/node": "^26.6.2",
56
+ "@typescript-eslint/parser": "^8.70.1",
57
+ "@vue/compiler-sfc": "^3.5.40",
58
+ "eslint": "^10.7.0",
59
+ "eslint-plugin-check-file": "^3.3.2",
60
+ "typescript": "6.0.3",
61
+ "typescript-eslint": "^8.70.1",
62
+ "vitest": "^4.1.10"
63
+ }
64
+ }