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.

Rule proposal: displayName matches filename

See original GitHub issue

As often happens in code copy-pasting, some component invariably has a displayName copied from another file.

It’d be fantastic to have a rule that requires the component name match the filename.

Positive tests:

  • Foo.js: React.createClass({ displayName:"Foo", ... })
  • Foo.jsx: React.createClass({ displayName:"Foo", ... })
  • Foo.es: React.createClass({ displayName:"Foo", ... })
  • FooComponent.jsx: React.createClass({ displayName:"FooComponent", ... })
  • Foo.js: React.createClass({ ... }) // no displayName specified — validated by separate rule

Negative tests:

  • FooComponent.js: React.createClass({ displayName:"Foo", ... })
  • Bar.js: React.createClass({ displayName:"Foo", ... })
  • Bar.js: React.createClass({ displayName:"", ... })

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:9
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Mar 28, 2020

The same naming convention should apply to an SFC as to a class component.

1reaction
ljharbcommented, Mar 29, 2020

For the old createClass pattern, yes, but that’s not something that’s reasonable for this lint rule to know about.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: displayName matches filename #157 - GitHub
It'd be fantastic to have a rule that requires the component name match the filename. Positive tests: Foo.js : React.createClass({ displayName:" ...
Read more >
Why does a saved attachment's file name include the name of ...
The method will search the attachment display name for a string match anywhere in the name, and assign it an ID accordingly. It...
Read more >
Windows Defender Firewall with Advanced Security ...
You can change the rule to match a different remote IP address of a Web ... –DisplayName “ah:sha1+esp:sha1-des3” -Proposal $AHandESPQM ...
Read more >
Naming Conventions · Styleguide JavaScript
Incorrect code for this rule: function s() { // ... } ... Filename Export Matching. A base filename should exactly match the name...
Read more >
How To: Search For Multiple Filenames At Once? - Capture One
Advanced Search with "Match Any of the following rules", and then each rule identifies one filename. E.G. "Display Name equals 20180823_SHOT_01_0036".
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