Skip to content

Commit eaeb4a6

Browse files
authored
Merge pull request #275 from callstack/platform-colors
feat: Enable `@react-native/platform-colors` rule
2 parents 3c61184 + cb05c25 commit eaeb4a6

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@babel/eslint-parser": "^7.22.15",
2424
"@babel/plugin-syntax-flow": "^7.22.5",
2525
"@babel/plugin-transform-react-jsx": "^7.22.15",
26+
"@react-native/eslint-plugin": "^0.74.0 || ^0.73.0 || ^0.72.0",
2627
"@typescript-eslint/eslint-plugin": "^6.7.2",
2728
"@typescript-eslint/parser": "^6.7.2",
2829
"eslint-config-prettier": "^9.0.0",
@@ -46,6 +47,6 @@
4647
"typescript": "^5.2.2"
4748
},
4849
"scripts": {
49-
"test": "yarn --cwd test && yarn --cwd test eslint --report-unused-disable-directives --ext .js,.ts,.jsx,.tsx ."
50+
"test": "yarn --cwd test && yarn --cwd test eslint --max-warnings 0 --report-unused-disable-directives --ext .js,.ts,.jsx,.tsx ."
5051
}
5152
}

react-native.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ module.exports = {
99
env: {
1010
'react-native/react-native': true,
1111
},
12-
plugins: ['react-native'],
12+
plugins: ['react-native', '@react-native'],
1313
rules: {
14+
'@react-native/platform-colors': WARNING,
1415
'react-native/no-unused-styles': ERROR,
1516
'react-native/split-platform-components': OFF,
1617
'react-native/no-inline-styles': WARNING,

test/PlatformColor.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { PlatformColor, DynamicColorIOS } from 'react-native';
2+
3+
// Invalid
4+
// eslint-disable-next-line @react-native/platform-colors
5+
PlatformColor(); // required at least one argument
6+
// eslint-disable-next-line @react-native/platform-colors
7+
PlatformColor([], {}); // arguments must be string literals
8+
// eslint-disable-next-line @react-native/platform-colors
9+
DynamicColorIOS('red'); // required object as first argument
10+
11+
// Valid
12+
PlatformColor('bogusName', 'linkColor');
13+
PlatformColor('label');
14+
PlatformColor('@android:color/holo_blue_bright');
15+
16+
export const customDynamicTextColor = DynamicColorIOS({
17+
dark: 'lightskyblue',
18+
light: 'midnightblue',
19+
});
20+
21+
export const customContrastDynamicTextColor = DynamicColorIOS({
22+
dark: 'darkgray',
23+
light: 'lightgray',
24+
highContrastDark: 'black',
25+
highContrastLight: 'white',
26+
});

test/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,11 @@
16121612
resolved "https://registry.yarnpkg.com/@react-native/assets/-/assets-1.0.0.tgz#c6f9bf63d274bafc8e970628de24986b30a55c8e"
16131613
integrity sha512-KrwSpS1tKI70wuKl68DwJZYEvXktDHdZMG0k2AXD/rJVSlB23/X2CB2cutVR0HwNMJIal9HOUOBB2rVfa6UGtQ==
16141614

1615+
"@react-native/eslint-plugin@^0.74.0 || ^0.73.0 || ^0.72.0":
1616+
version "0.74.84"
1617+
resolved "https://registry.yarnpkg.com/@react-native/eslint-plugin/-/eslint-plugin-0.74.84.tgz#f0e9618551c9340caca7624001f8ce32794715c9"
1618+
integrity sha512-pDzo4Qm1uPZQne2sv0QK89ePxP/i+ZHjrBW3rkTVStLvsDVdyFahMmt6bzJTdYL2cGgK2oyNmfXtvO57INOu3Q==
1619+
16151620
"@react-native/normalize-color@2.0.0":
16161621
version "2.0.0"
16171622
resolved "https://registry.yarnpkg.com/@react-native/normalize-color/-/normalize-color-2.0.0.tgz#da955909432474a9a0fe1cbffc66576a0447f567"

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@
405405
picocolors "^1.0.0"
406406
tslib "^2.6.0"
407407

408+
"@react-native/eslint-plugin@^0.74.0 || ^0.73.0 || ^0.72.0":
409+
version "0.74.84"
410+
resolved "https://registry.yarnpkg.com/@react-native/eslint-plugin/-/eslint-plugin-0.74.84.tgz#f0e9618551c9340caca7624001f8ce32794715c9"
411+
integrity sha512-pDzo4Qm1uPZQne2sv0QK89ePxP/i+ZHjrBW3rkTVStLvsDVdyFahMmt6bzJTdYL2cGgK2oyNmfXtvO57INOu3Q==
412+
408413
"@types/json-schema@^7.0.12":
409414
version "7.0.12"
410415
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"

0 commit comments

Comments
 (0)