question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sort-comp wrong order with RegExp rules and static methods

See original GitHub issue

I believe this issues comes from #1795

The Airbnb rules for react include sort-comp with regex matching. source here

If you have a static method that matches any of the 3 RegExp values (e.g. renderCell) then this will push to indexes, and the following check for method.static will not happen because of the new conditional on empty indexes.

This should be valid according to the Airbnb Rules.

class Row extends React.Component {
  static getDelta(data) {
    ...
  }

  static onTimeout() {
    ...
  }

  static renderCell(data) {
    ...
  }

  constructor(props) {
    ...
  }

  render() {
    ...
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
nosillegcommented, Jun 26, 2018

I’m creating a PR. The fix is a bit more involved than a revert or added RegExp check.

0reactions
nosillegcommented, Jun 26, 2018

I have no doubt that havinggDDFP in lifecycle is a valid view. I’m willing to bet others think having it with statics is preferable. The precedence set with RegExps when this rule was first created is that things can appear in any matching group.

Making it more strict would require going back to your original PR commit and having explicit exceptions to rules. It may be the case that my PR will be a partial revert of your PR in your eyes, since it’s less strict.

Allowing static methods/properties to be in multiple places fixes two additional issues. #1838 and #1808

I’ll push the PR and see what the feedback is. It should be done shortly after adding a test for an undiscovered bug that my changes fix. (While hopefully not breaking things we don’t have tests for.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

sort-comp wrong order with RegExp rules and static methods
I believe this issues comes from #1795 The Airbnb rules for react include sort-comp with regex matching. source here If you have a...
Read more >
Regular Expression (Regex) Tutorial
A regex (regular expression) consists of a sequence of sub-expressions. In this example ... Regex to be matched // Step 1: Compile a...
Read more >
Regular expression syntax cheatsheet - JavaScript | MDN
This page provides an overall cheat sheet of all the capabilities of RegExp syntax by aggregating the content of the articles in the...
Read more >
Best Practices for Regular Expressions in .NET - Microsoft Learn
Text that matches the regular expression pattern. ... Static regular expression methods are recommended as an alternative to repeatedly ...
Read more >
A Practical Guide to Regular Expressions (RegEx) In JavaScript
In order to fully understand the regex world you first need to learn the basics concepts, ... There are mainly two methods for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found