Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable @react-native/platform-colors rule #275

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-syntax-flow": "^7.22.5",
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@react-native/eslint-plugin": "^0.74.0 || ^0.73.0 || ^0.72.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint-config-prettier": "^9.0.0",
Expand All @@ -46,6 +47,6 @@
"typescript": "^5.2.2"
},
"scripts": {
"test": "yarn --cwd test && yarn --cwd test eslint --report-unused-disable-directives --ext .js,.ts,.jsx,.tsx ."
"test": "yarn --cwd test && yarn --cwd test eslint --max-warnings 0 --report-unused-disable-directives --ext .js,.ts,.jsx,.tsx ."
}
}
3 changes: 2 additions & 1 deletion react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = {
env: {
'react-native/react-native': true,
},
plugins: ['react-native'],
plugins: ['react-native', '@react-native'],
rules: {
'@react-native/platform-colors': WARNING,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we turn on all recommended rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@react-native plugin is exported only one rule )

'react-native/no-unused-styles': ERROR,
'react-native/split-platform-components': OFF,
'react-native/no-inline-styles': WARNING,
Expand Down
27 changes: 27 additions & 0 deletions test/PlatformColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PlatformColor, DynamicColorIOS } from 'react-native';

// Invalid
// eslint-disable-next-line @react-native/platform-colors
PlatformColor(); // required at least one argument
// eslint-disable-next-line @react-native/platform-colors
PlatformColor([], {}); // arguments must be string literals
// eslint-disable-next-line @react-native/platform-colors
DynamicColorIOS('red'); // required object as first argument
Comment on lines +5 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh looks like TS should take care of these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course TS will catch it early
but it still useful for JS projects


// Valid
PlatformColor('bogusName', 'linkColor');

retyui marked this conversation as resolved.
Show resolved Hide resolved
PlatformColor('label');
PlatformColor('@android:color/holo_blue_bright');

export const customDynamicTextColor = DynamicColorIOS({
dark: 'lightskyblue',
light: 'midnightblue',
});

export const customContrastDynamicTextColor = DynamicColorIOS({
dark: 'darkgray',
light: 'lightgray',
highContrastDark: 'black',
highContrastLight: 'white',
});
5 changes: 5 additions & 0 deletions test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,11 @@
resolved "https://registry.yarnpkg.com/@react-native/assets/-/assets-1.0.0.tgz#c6f9bf63d274bafc8e970628de24986b30a55c8e"
integrity sha512-KrwSpS1tKI70wuKl68DwJZYEvXktDHdZMG0k2AXD/rJVSlB23/X2CB2cutVR0HwNMJIal9HOUOBB2rVfa6UGtQ==

"@react-native/eslint-plugin@^0.74.0 || ^0.73.0 || ^0.72.0":
version "0.74.84"
resolved "https://registry.yarnpkg.com/@react-native/eslint-plugin/-/eslint-plugin-0.74.84.tgz#f0e9618551c9340caca7624001f8ce32794715c9"
integrity sha512-pDzo4Qm1uPZQne2sv0QK89ePxP/i+ZHjrBW3rkTVStLvsDVdyFahMmt6bzJTdYL2cGgK2oyNmfXtvO57INOu3Q==

"@react-native/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@react-native/normalize-color/-/normalize-color-2.0.0.tgz#da955909432474a9a0fe1cbffc66576a0447f567"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@
picocolors "^1.0.0"
tslib "^2.6.0"

"@react-native/eslint-plugin@^0.74.0 || ^0.73.0 || ^0.72.0":
version "0.74.84"
resolved "https://registry.yarnpkg.com/@react-native/eslint-plugin/-/eslint-plugin-0.74.84.tgz#f0e9618551c9340caca7624001f8ce32794715c9"
integrity sha512-pDzo4Qm1uPZQne2sv0QK89ePxP/i+ZHjrBW3rkTVStLvsDVdyFahMmt6bzJTdYL2cGgK2oyNmfXtvO57INOu3Q==

"@types/json-schema@^7.0.12":
version "7.0.12"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"
Expand Down
Loading