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

Rule idea: check for known values #2

Open
kristerkari opened this issue Feb 15, 2018 · 7 comments
Open

Rule idea: check for known values #2

kristerkari opened this issue Feb 15, 2018 · 7 comments
Labels
help wanted Extra attention is needed new rule

Comments

@kristerkari
Copy link
Owner

There could a be a rule that checks for valid values for styling properties that are supported by React Native.

React Native documentation already list the valid values and those are also probably available in the repo:
https://facebook.github.io/react-native/docs/layout-props.html

@kristerkari kristerkari added new rule help wanted Extra attention is needed labels Feb 15, 2018
@arvigeus
Copy link
Contributor

arvigeus commented Sep 2, 2018

Will this help? .stylelintrc.json

@kristerkari
Copy link
Owner Author

@arvigeus There is already a rule that does that: https://github.com/kristerkari/stylelint-react-native/blob/master/src/rules/css-property-no-unknown/README.md#css-property-no-unknown

This idea was for checking valid values for those properties.

@jason1985
Copy link

@kristerkari Hi!
I know this is super old, but was there a current way to lint for valid values for styling properties that are supported by React Native?

invalid for React Native:

height: '30px',

valid value for React Native:

height: 30,

I'm just looking for an easy solution to lint for both valid properties and values for React Native styles.

Thanks!

@kristerkari
Copy link
Owner Author

@jason1985 No worries.

Honestly, I don't see much point to add linting for the example that you gave, since it can be easily avoided if you use Typescript and add typings to your styles.

@jason1985
Copy link

jason1985 commented Nov 17, 2021

@kristerkari Thanks so much for your response!

Works great however do you know of somewhere that has these types already or do I need to manually make them?
I feel like someone must have already done this.

I've found this https://github.com/vhpoet/react-native-styling-cheat-sheet which is getting the info from the docs https://reactnative.dev/docs/layout-props (the link you posted).

I have something like this so far:

type Style = {
  alignSelf?: "auto" | "flex-start" | "flex-end" | "center" | "stretch" | "baseline"
  backgroundColor?: string
  borderColor?: string
  borderRadius?: number
  borderWidth?: number
  color?: string
  elevation?: number
  flex?: number
  flexDirection?: "row" | "row-reverse" | "column" | "column-reverse"
  fontFamily?: string
  fontSize?: number
  fontWeight?: "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900"
  height?: number
  // etc.
}

Thank you!

@jason1985
Copy link

Just an update in the off chance someone else happens to read this and not know.
I found all the possible react native style types defined by TextStyle and StyleSheet.

import {TextStyle, StyleSheet} from 'react-native'

const exampleStyles: ViewStyle | TextStyle = {
  // Intellisense works here
}

file location: ./node_modules/@types/react-native/index.d.ts

@kristerkari
Copy link
Owner Author

@jason1985 yes, that's good way to do it. Just assign the style object the ViewStyle, TextStyle, etc. depending on which element the styles get applied to 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed new rule
Projects
None yet
Development

No branches or pull requests

3 participants