Skip to content

Allow using StringLiteral as properties of StyleSheet #215

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

Merged

Conversation

shirohana
Copy link
Contributor

Try to fix #213

After Patch

Now we can lint some simple template string like: (with default configs)

const styles = StyleSheet.create({
  'Text--underlined': {},
  'Text--basic': {}
})

// `error  Expected class names to be in ascending order.
//    'Text--basic' should be before 'Text--underlined'  react-native/sort-styles`
const prefix = 'Text'
const styles = StyleSheet.create({
  [`${prefix}Wrapper`]: {},
  [`${prefix}Container`]: {}
})

// `error  Expected class names to be in ascending order.
//    'TextContainer' should be before 'TextWrapper'  react-native/sort-styles`

By the way, other expressions like BinaryExpression or AssignmentExpression was not implemented yet.
I think it is a little bit abusing StyleSheet?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 75.097% when pulling 9e13485 on shirohana:fix/literal-stylesheet-property into 35f7e07 on Intellicode:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 75.097% when pulling 9e13485 on shirohana:fix/literal-stylesheet-property into 35f7e07 on Intellicode:master.

@Intellicode Intellicode merged commit 89c3a11 into Intellicode:master Feb 10, 2019
@Intellicode
Copy link
Owner

@shirohana Thanks for your PR!

The initial rules were probably designed for the most simple use cases (I haven't created this rule). I suppose if there is a valid use case for BinaryExpression or AssignmentExpression it can certainly be added.

@shirohana shirohana deleted the fix/literal-stylesheet-property branch February 10, 2019 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sort-styles has a problem with detecting computed property names
3 participants