diff --git a/.eslintrc.js b/.eslintrc.js index ecfa6f0..e607ef7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,8 +9,10 @@ module.exports = { }, }, ], - plugins: ['prettier', 'eslint-plugin-react-compiler'], + + plugins: ['prettier', 'eslint-plugin-react-compiler', 'internal'], rules: { + 'internal/enforce-spacing-values': 'error', 'react-compiler/react-compiler': 'error', 'prettier/prettier': [ 'error', diff --git a/eslint/eslint-plugin-enforce-spacing-values.js b/eslint/eslint-plugin-enforce-spacing-values.js new file mode 100644 index 0000000..68fd175 --- /dev/null +++ b/eslint/eslint-plugin-enforce-spacing-values.js @@ -0,0 +1,53 @@ +const allowedValues = [2, 4, 8, 12, 16, 24] + +module.exports = { + meta: { + type: 'suggestion', + docs: { + description: 'Enforce border, padding, and margin values to be 2, 4, 8, 12, or 16', + category: 'Stylistic Issues', + recommended: false, + }, + schema: [], // no options + messages: { + invalidValue: `The value '{{value}}' for '{{property}}' is not allowed. Use ${allowedValues.toString()} instead.`, + }, + }, + create(context) { + const relevantProperties = [ + 'margin', + 'marginTop', + 'marginBottom', + 'marginLeft', + 'marginRight', + 'marginHorizontal', + 'marginVertical', + 'padding', + 'paddingTop', + 'paddingBottom', + 'paddingLeft', + 'paddingRight', + 'paddingHorizontal', + 'paddingVertical', + 'borderRadius', + ] + + return { + Property(node) { + if (relevantProperties.includes(node.key.name)) { + const value = node.value.value + if (typeof value === 'number' && !allowedValues.includes(value)) { + context.report({ + node, + messageId: 'invalidValue', + data: { + value, + property: node.key.name, + }, + }) + } + } + }, + } + }, +} diff --git a/eslint/index.js b/eslint/index.js new file mode 100644 index 0000000..bf121c5 --- /dev/null +++ b/eslint/index.js @@ -0,0 +1,8 @@ +/* eslint-disable object-shorthand */ +// eslint-plugin-react-native-stylesheet/index.js + +module.exports = { + rules: { + 'enforce-spacing-values': require('./eslint-plugin-enforce-spacing-values'), + }, +} diff --git a/package-lock.json b/package-lock.json index 8504008..da4523e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "babel-plugin-inline-import": "^3.0.0", "babel-plugin-react-compiler": "^19.0.0-beta-a7bf2bd-20241110", "cui-fs": "^0.1.2", - "cui-llama.rn": "^1.4.1", + "cui-llama.rn": "^1.4.2", "drizzle-orm": "^0.36.2", "eas-cli": "^14.5.0", "eslint-plugin-react-compiler": "^0.0.0-experimental-7c1344f-20241009", @@ -76,6 +76,7 @@ "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-config-universe": "^12.0.0", + "eslint-plugin-internal": "file:./eslint", "eslint-plugin-prettier": "^5.1.3", "i18next-scanner": "^4.6.0", "patch-package": "^8.0.0", @@ -83,6 +84,9 @@ "typescript": "~5.3.3" } }, + "eslint": { + "dev": true + }, "node_modules/@0no-co/graphql.web": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@0no-co/graphql.web/-/graphql.web-1.0.8.tgz", @@ -10658,9 +10662,9 @@ } }, "node_modules/cui-llama.rn": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/cui-llama.rn/-/cui-llama.rn-1.4.1.tgz", - "integrity": "sha512-P/WGcAJdPe3yFQzBHp673zlC5j+i3lYMQOli5wutIUnej3fzQ5Zu2H3t/AuBtJtRyR1R72guGXX9OseboEem9g==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/cui-llama.rn/-/cui-llama.rn-1.4.2.tgz", + "integrity": "sha512-6qKWeZAMRjSgNEGCUVh1KNnB4hUHPBE9Aa605Oy0gsQBiq0yA2pYzkbRcefvJ1bXQ6AOwxfWkFLlpNq3Tgbi6g==", "license": "MIT", "engines": { "node": ">= 16.0.0" @@ -12402,6 +12406,10 @@ "node": "*" } }, + "node_modules/eslint-plugin-internal": { + "resolved": "eslint", + "link": true + }, "node_modules/eslint-plugin-node": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz", diff --git a/package.json b/package.json index df17276..a72ca3b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "babel-plugin-inline-import": "^3.0.0", "babel-plugin-react-compiler": "^19.0.0-beta-a7bf2bd-20241110", "cui-fs": "^0.1.2", - "cui-llama.rn": "^1.4.1", + "cui-llama.rn": "^1.4.2", "drizzle-orm": "^0.36.2", "eas-cli": "^14.5.0", "eslint-plugin-react-compiler": "^0.0.0-experimental-7c1344f-20241009", @@ -87,6 +87,7 @@ "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-config-universe": "^12.0.0", + "eslint-plugin-internal": "file:./eslint", "eslint-plugin-prettier": "^5.1.3", "i18next-scanner": "^4.6.0", "patch-package": "^8.0.0",