@kivacore/rules 0.0.0 → 0.8.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 (57) hide show
  1. package/README.md +234 -1
  2. package/dist/biome/astro.json +28 -0
  3. package/dist/biome/base.json +34 -0
  4. package/dist/biome/cloudflare.json +69 -0
  5. package/dist/biome/electron.json +28 -0
  6. package/dist/biome/nextjs.json +41 -0
  7. package/dist/biome/react.json +41 -0
  8. package/dist/biome/vue.json +28 -0
  9. package/dist/eslint/ai.d.ts +3 -0
  10. package/dist/eslint/ai.d.ts.map +1 -0
  11. package/dist/eslint/ai.js +13 -0
  12. package/dist/eslint/astro.d.ts +3 -0
  13. package/dist/eslint/astro.d.ts.map +1 -0
  14. package/dist/eslint/astro.js +2 -0
  15. package/dist/eslint/base.d.ts +3 -0
  16. package/dist/eslint/base.d.ts.map +1 -0
  17. package/dist/eslint/base.js +368 -0
  18. package/dist/eslint/electron.d.ts +3 -0
  19. package/dist/eslint/electron.d.ts.map +1 -0
  20. package/dist/eslint/electron.js +44 -0
  21. package/dist/eslint/index.d.ts +9 -0
  22. package/dist/eslint/index.d.ts.map +1 -0
  23. package/dist/eslint/index.js +8 -0
  24. package/dist/eslint/nextjs.d.ts +3 -0
  25. package/dist/eslint/nextjs.d.ts.map +1 -0
  26. package/dist/eslint/nextjs.js +26 -0
  27. package/dist/eslint/react-native.d.ts +3 -0
  28. package/dist/eslint/react-native.d.ts.map +1 -0
  29. package/dist/eslint/react-native.js +19 -0
  30. package/dist/eslint/react.d.ts +3 -0
  31. package/dist/eslint/react.d.ts.map +1 -0
  32. package/dist/eslint/react.js +20 -0
  33. package/dist/eslint/rules/index.d.ts +3 -0
  34. package/dist/eslint/rules/index.d.ts.map +1 -0
  35. package/dist/eslint/rules/index.js +14 -0
  36. package/dist/eslint/rules/react-native-no-color-literals.d.ts +3 -0
  37. package/dist/eslint/rules/react-native-no-color-literals.d.ts.map +1 -0
  38. package/dist/eslint/rules/react-native-no-color-literals.js +84 -0
  39. package/dist/eslint/rules/react-native-no-inline-styles.d.ts +3 -0
  40. package/dist/eslint/rules/react-native-no-inline-styles.d.ts.map +1 -0
  41. package/dist/eslint/rules/react-native-no-inline-styles.js +36 -0
  42. package/dist/eslint/rules/react-native-no-raw-text.d.ts +3 -0
  43. package/dist/eslint/rules/react-native-no-raw-text.d.ts.map +1 -0
  44. package/dist/eslint/rules/react-native-no-raw-text.js +85 -0
  45. package/dist/eslint/rules/react-native-no-single-element-style-arrays.d.ts +3 -0
  46. package/dist/eslint/rules/react-native-no-single-element-style-arrays.d.ts.map +1 -0
  47. package/dist/eslint/rules/react-native-no-single-element-style-arrays.js +33 -0
  48. package/dist/eslint/rules/react-native-no-unused-styles.d.ts +3 -0
  49. package/dist/eslint/rules/react-native-no-unused-styles.d.ts.map +1 -0
  50. package/dist/eslint/rules/react-native-no-unused-styles.js +51 -0
  51. package/dist/eslint/rules/react-native-split-platform-components.d.ts +3 -0
  52. package/dist/eslint/rules/react-native-split-platform-components.d.ts.map +1 -0
  53. package/dist/eslint/rules/react-native-split-platform-components.js +66 -0
  54. package/dist/eslint/vue.d.ts +3 -0
  55. package/dist/eslint/vue.d.ts.map +1 -0
  56. package/dist/eslint/vue.js +27 -0
  57. package/package.json +96 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-no-inline-styles.d.ts","sourceRoot":"","sources":["../../../src/eslint/rules/react-native-no-inline-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,eAAO,MAAM,cAAc,EAAE,IAAI,CAAC,UAqCjC,CAAC"}
@@ -0,0 +1,36 @@
1
+ export const noInlineStyles = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ docs: {
5
+ description: 'Disallow inline styles in JSX, prefer StyleSheet.create'
6
+ },
7
+ schema: []
8
+ },
9
+ create(context) {
10
+ return {
11
+ JSXAttribute(node) {
12
+ if (node.name?.name !== 'style')
13
+ return;
14
+ const expr = node.value?.expression;
15
+ if (!expr)
16
+ return;
17
+ if (expr.type === 'ObjectExpression') {
18
+ context.report({
19
+ node: expr,
20
+ message: 'Inline styles are not allowed. Use StyleSheet.create instead'
21
+ });
22
+ }
23
+ if (expr.type === 'ArrayExpression') {
24
+ for (const element of expr.elements) {
25
+ if (element?.type === 'ObjectExpression') {
26
+ context.report({
27
+ node: element,
28
+ message: 'Inline styles are not allowed. Use StyleSheet.create instead'
29
+ });
30
+ }
31
+ }
32
+ }
33
+ }
34
+ };
35
+ }
36
+ };
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ export declare const noRawText: Rule.RuleModule;
3
+ //# sourceMappingURL=react-native-no-raw-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-no-raw-text.d.ts","sourceRoot":"","sources":["../../../src/eslint/rules/react-native-no-raw-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAUnC,eAAO,MAAM,SAAS,EAAE,IAAI,CAAC,UAqF5B,CAAC"}
@@ -0,0 +1,85 @@
1
+ const TEXT_COMPONENTS = new Set([
2
+ 'Text',
3
+ 'TText',
4
+ 'StyledText',
5
+ 'AnimatedText',
6
+ 'Animated.Text'
7
+ ]);
8
+ export const noRawText = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'Disallow raw text outside of Text components in React Native'
13
+ },
14
+ schema: [
15
+ {
16
+ type: 'object',
17
+ properties: {
18
+ skip: {
19
+ type: 'array',
20
+ items: { type: 'string' }
21
+ }
22
+ },
23
+ additionalProperties: false
24
+ }
25
+ ]
26
+ },
27
+ create(context) {
28
+ const options = context.options[0];
29
+ const allowedComponents = new Set([...TEXT_COMPONENTS, ...(options?.skip || [])]);
30
+ function getJSXElementName(node) {
31
+ if (node.type !== 'JSXOpeningElement')
32
+ return null;
33
+ const { name } = node;
34
+ if (name.type === 'JSXIdentifier')
35
+ return name.name;
36
+ if (name.type === 'JSXMemberExpression') {
37
+ return `${name.object.name}.${name.property.name}`;
38
+ }
39
+ return null;
40
+ }
41
+ function isTextComponent(node) {
42
+ let current = node;
43
+ while (current) {
44
+ if (current.type === 'JSXElement') {
45
+ const name = getJSXElementName(current.openingElement);
46
+ if (name && allowedComponents.has(name))
47
+ return true;
48
+ }
49
+ current = current.parent || null;
50
+ }
51
+ return false;
52
+ }
53
+ return {
54
+ JSXText(node) {
55
+ if (!node.value.trim())
56
+ return;
57
+ if (isTextComponent(node))
58
+ return;
59
+ context.report({
60
+ node,
61
+ message: 'Raw text must be wrapped in a <Text> component'
62
+ });
63
+ },
64
+ JSXExpressionContainer(node) {
65
+ const expr = node.expression;
66
+ if (expr.type === 'Literal' && typeof expr.value === 'string') {
67
+ if (isTextComponent(node))
68
+ return;
69
+ context.report({
70
+ node,
71
+ message: 'Raw text must be wrapped in a <Text> component'
72
+ });
73
+ }
74
+ if (expr.type === 'TemplateLiteral') {
75
+ if (isTextComponent(node))
76
+ return;
77
+ context.report({
78
+ node,
79
+ message: 'Raw text must be wrapped in a <Text> component'
80
+ });
81
+ }
82
+ }
83
+ };
84
+ }
85
+ };
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ export declare const noSingleElementStyleArrays: Rule.RuleModule;
3
+ //# sourceMappingURL=react-native-no-single-element-style-arrays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-no-single-element-style-arrays.d.ts","sourceRoot":"","sources":["../../../src/eslint/rules/react-native-no-single-element-style-arrays.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,eAAO,MAAM,0BAA0B,EAAE,IAAI,CAAC,UAmC7C,CAAC"}
@@ -0,0 +1,33 @@
1
+ export const noSingleElementStyleArrays = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ docs: {
5
+ description: 'Disallow single-element style arrays, which cause unnecessary re-renders'
6
+ },
7
+ fixable: 'code',
8
+ schema: []
9
+ },
10
+ create(context) {
11
+ return {
12
+ JSXAttribute(node) {
13
+ if (node.name?.name !== 'style')
14
+ return;
15
+ const expr = node.value?.expression;
16
+ if (!expr || expr.type !== 'ArrayExpression' || expr.elements.length !== 1)
17
+ return;
18
+ const element = expr.elements[0];
19
+ if (!element)
20
+ return;
21
+ context.report({
22
+ node: expr,
23
+ message: 'Single-element style arrays are not necessary and cause unnecessary re-renders',
24
+ fix(fixer) {
25
+ const { sourceCode } = context;
26
+ const elementText = sourceCode.getText(element);
27
+ return fixer.replaceText(expr, elementText);
28
+ }
29
+ });
30
+ }
31
+ };
32
+ }
33
+ };
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ export declare const noUnusedStyles: Rule.RuleModule;
3
+ //# sourceMappingURL=react-native-no-unused-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-no-unused-styles.d.ts","sourceRoot":"","sources":["../../../src/eslint/rules/react-native-no-unused-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,eAAO,MAAM,cAAc,EAAE,IAAI,CAAC,UA0DjC,CAAC"}
@@ -0,0 +1,51 @@
1
+ export const noUnusedStyles = {
2
+ meta: {
3
+ type: 'problem',
4
+ docs: {
5
+ description: 'Detect StyleSheet.create styles that are not used'
6
+ },
7
+ schema: []
8
+ },
9
+ create(context) {
10
+ const definedStyles = new Map();
11
+ const usedStyles = new Set();
12
+ return {
13
+ CallExpression(node) {
14
+ if (node.callee.type !== 'MemberExpression'
15
+ || node.callee.object.type !== 'Identifier'
16
+ || node.callee.object.name !== 'StyleSheet'
17
+ || node.callee.property.type !== 'Identifier'
18
+ || node.callee.property.name !== 'create')
19
+ return;
20
+ const { parent } = node;
21
+ if (parent?.type !== 'VariableDeclarator' || parent.id.type !== 'Identifier')
22
+ return;
23
+ const objectName = parent.id.name;
24
+ const arg = node.arguments[0];
25
+ if (arg?.type !== 'ObjectExpression')
26
+ return;
27
+ for (const prop of arg.properties) {
28
+ if (prop.type === 'Property' && prop.key.type === 'Identifier') {
29
+ const key = `${objectName}.${prop.key.name}`;
30
+ definedStyles.set(key, { objectName, propertyName: prop.key.name, node: prop });
31
+ }
32
+ }
33
+ },
34
+ MemberExpression(node) {
35
+ if (node.object.type === 'Identifier' && node.property.type === 'Identifier') {
36
+ usedStyles.add(`${node.object.name}.${node.property.name}`);
37
+ }
38
+ },
39
+ 'Program:exit'() {
40
+ for (const [key, { propertyName, node }] of definedStyles) {
41
+ if (!usedStyles.has(key)) {
42
+ context.report({
43
+ node,
44
+ message: `Unused style detected: '${propertyName}'`
45
+ });
46
+ }
47
+ }
48
+ }
49
+ };
50
+ }
51
+ };
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ export declare const splitPlatformComponents: Rule.RuleModule;
3
+ //# sourceMappingURL=react-native-split-platform-components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-split-platform-components.d.ts","sourceRoot":"","sources":["../../../src/eslint/rules/react-native-split-platform-components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAwBnC,eAAO,MAAM,uBAAuB,EAAE,IAAI,CAAC,UAqD1C,CAAC"}
@@ -0,0 +1,66 @@
1
+ const IOS_COMPONENTS = [
2
+ 'DatePickerIOS',
3
+ 'ProgressViewIOS',
4
+ 'SearchBarIOS',
5
+ 'TabBarIOS',
6
+ 'TabBarIOS.Item'
7
+ ];
8
+ const ANDROID_COMPONENTS = [
9
+ 'DrawerLayoutAndroid',
10
+ 'ProgressBarAndroid',
11
+ 'ToolbarAndroid',
12
+ 'ViewPagerAndroid',
13
+ 'ToastAndroid',
14
+ 'TouchableNativeFeedback'
15
+ ];
16
+ export const splitPlatformComponents = {
17
+ meta: {
18
+ type: 'suggestion',
19
+ docs: {
20
+ description: 'Enforce platform-specific components are used in platform-specific files'
21
+ },
22
+ schema: [
23
+ {
24
+ type: 'object',
25
+ properties: {
26
+ iosPathRegex: { type: 'string' },
27
+ androidPathRegex: { type: 'string' }
28
+ },
29
+ additionalProperties: false
30
+ }
31
+ ]
32
+ },
33
+ create(context) {
34
+ const options = (context.options[0] || {});
35
+ const iosRegex = new RegExp(options.iosPathRegex || '\\.ios\\.[jt]sx?$');
36
+ const androidRegex = new RegExp(options.androidPathRegex || '\\.android\\.[jt]sx?$');
37
+ const filename = context.filename || '';
38
+ const isIOS = iosRegex.test(filename);
39
+ const isAndroid = androidRegex.test(filename);
40
+ function checkComponent(node, name) {
41
+ if (IOS_COMPONENTS.includes(name) && !isIOS) {
42
+ context.report({
43
+ node,
44
+ message: `'${name}' is an iOS-only component. Use it in a file matching ${iosRegex.source}`
45
+ });
46
+ }
47
+ if (ANDROID_COMPONENTS.includes(name) && !isAndroid) {
48
+ context.report({
49
+ node,
50
+ message: `'${name}' is an Android-only component. Use it in a file matching ${androidRegex.source}`
51
+ });
52
+ }
53
+ }
54
+ return {
55
+ ImportDeclaration(node) {
56
+ if (node.source.value !== 'react-native')
57
+ return;
58
+ for (const specifier of node.specifiers) {
59
+ if (specifier.type === 'ImportSpecifier' && specifier.imported.type === 'Identifier') {
60
+ checkComponent(specifier, specifier.imported.name);
61
+ }
62
+ }
63
+ }
64
+ };
65
+ }
66
+ };
@@ -0,0 +1,3 @@
1
+ import { type Linter } from 'eslint';
2
+ export declare const vueConfig: Linter.Config[];
3
+ //# sourceMappingURL=vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../src/eslint/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKrC,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAwBpC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import vuePlugin from 'eslint-plugin-vue';
2
+ import vueParser from 'vue-eslint-parser';
3
+ export const vueConfig = [
4
+ ...vuePlugin.configs['flat/recommended'],
5
+ {
6
+ files: ['**/*.vue'],
7
+ languageOptions: {
8
+ parser: vueParser,
9
+ parserOptions: {
10
+ ecmaVersion: 'latest',
11
+ sourceType: 'module'
12
+ }
13
+ },
14
+ rules: {
15
+ 'vue/multi-word-component-names': 'off',
16
+ 'vue/html-end-tags': 'error',
17
+ 'vue/html-closing-bracket-spacing': [
18
+ 'error',
19
+ {
20
+ startTag: 'always',
21
+ endTag: 'never',
22
+ selfClosingTag: 'always'
23
+ }
24
+ ]
25
+ }
26
+ }
27
+ ];
package/package.json CHANGED
@@ -1,10 +1,103 @@
1
1
  {
2
2
  "name": "@kivacore/rules",
3
- "version": "0.0.0",
4
- "description": "Placeholder that lets CI publish this package with npm trusted publishing. Install the latest version.",
3
+ "version": "0.8.0",
5
4
  "repository": {
6
5
  "type": "git",
7
6
  "url": "https://github.com/Docyrus/docyrus-devkit.git",
8
7
  "directory": "packages/rules"
8
+ },
9
+ "description": "Shared ESLint and Biome configurations for Docyrus projects",
10
+ "type": "module",
11
+ "exports": {
12
+ "./eslint": {
13
+ "types": "./dist/eslint/index.d.ts",
14
+ "default": "./dist/eslint/index.js"
15
+ },
16
+ "./eslint/base": {
17
+ "types": "./dist/eslint/base.d.ts",
18
+ "default": "./dist/eslint/base.js"
19
+ },
20
+ "./eslint/react": {
21
+ "types": "./dist/eslint/react.d.ts",
22
+ "default": "./dist/eslint/react.js"
23
+ },
24
+ "./eslint/nextjs": {
25
+ "types": "./dist/eslint/nextjs.d.ts",
26
+ "default": "./dist/eslint/nextjs.js"
27
+ },
28
+ "./eslint/ai": {
29
+ "types": "./dist/eslint/ai.d.ts",
30
+ "default": "./dist/eslint/ai.js"
31
+ },
32
+ "./eslint/vue": {
33
+ "types": "./dist/eslint/vue.d.ts",
34
+ "default": "./dist/eslint/vue.js"
35
+ },
36
+ "./eslint/astro": {
37
+ "types": "./dist/eslint/astro.d.ts",
38
+ "default": "./dist/eslint/astro.js"
39
+ },
40
+ "./eslint/react-native": {
41
+ "types": "./dist/eslint/react-native.d.ts",
42
+ "default": "./dist/eslint/react-native.js"
43
+ },
44
+ "./eslint/electron": {
45
+ "types": "./dist/eslint/electron.d.ts",
46
+ "default": "./dist/eslint/electron.js"
47
+ },
48
+ "./biome/base": "./dist/biome/base.json",
49
+ "./biome/cloudflare": "./dist/biome/cloudflare.json",
50
+ "./biome/react": "./dist/biome/react.json",
51
+ "./biome/nextjs": "./dist/biome/nextjs.json",
52
+ "./biome/electron": "./dist/biome/electron.json",
53
+ "./biome/astro": "./dist/biome/astro.json",
54
+ "./biome/vue": "./dist/biome/vue.json"
55
+ },
56
+ "files": [
57
+ "dist"
58
+ ],
59
+ "dependencies": {
60
+ "@eslint-react/eslint-plugin": "5.30.3",
61
+ "@next/eslint-plugin-next": "16.4.6",
62
+ "@stylistic/eslint-plugin": "5.10.0",
63
+ "@typescript-eslint/eslint-plugin": "8.72.2",
64
+ "@typescript-eslint/parser": "8.72.2",
65
+ "enhanced-resolve": "5.27.0",
66
+ "eslint-import-resolver-typescript": "4.4.5",
67
+ "eslint-plugin-astro": "1.7.0",
68
+ "eslint-plugin-import-x": "4.18.1",
69
+ "eslint-plugin-n": "18.5.0",
70
+ "eslint-plugin-react-hooks": "7.1.1",
71
+ "eslint-plugin-unused-imports": "4.4.1",
72
+ "eslint-plugin-vercel-ai-security": "1.5.4",
73
+ "eslint-plugin-vue": "10.12.1",
74
+ "globals": "17.14.0",
75
+ "vue-eslint-parser": "10.4.2"
76
+ },
77
+ "devDependencies": {
78
+ "eslint": "10.15.0",
79
+ "typescript": "7.0.2",
80
+ "vitest": "5.1.0"
81
+ },
82
+ "peerDependencies": {
83
+ "@biomejs/biome": "^2.4.0",
84
+ "eslint": "^10",
85
+ "typescript": "^5.9.0 || ^6.0.0"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "@biomejs/biome": {
89
+ "optional": true
90
+ }
91
+ },
92
+ "scripts": {
93
+ "build": "tsc && rm -rf dist/biome && cp -r src/biome dist/biome",
94
+ "clean": "rm -rf dist",
95
+ "verify": "node --input-type=module -e \"import { baseConfig, reactConfig, reactNativeConfig, nextjsConfig, aiConfig, vueConfig, astroConfig, electronConfig } from '@kivacore/rules/eslint'; console.log('All exports OK');\"",
96
+ "lint": "eslint src",
97
+ "format": "eslint src --fix",
98
+ "typecheck": "eslint src && tsc --noEmit",
99
+ "test": "vitest run --passWithNoTests",
100
+ "test:watch": "vitest",
101
+ "deploy": "pnpm run clean && pnpm run build && pnpm publish --access public"
9
102
  }
10
- }
103
+ }