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.

no-unexpected-multiline rule clashes with Prettier

See original GitHub issue

I am using TypeScript, Prettier (1.17.0) and styled-components in a CRA app. When I define the prop types of my styled components inline, I end up with constructs like these:

const Component = styled.div<{
  prop1?: Type;
  prop2?: Type;
}>`
  /* Some styles here... */
`;

The above is the formatting chosen by Prettier. However, CRA’s ESLint config doesn’t seem to agree:

Line 1:  Unexpected newline between template tag and template literal  no-unexpected-multiline [no-unexpected-multiline]

This means that when I use the pattern above, it is impossible for me to use ESLint and create-react-app together without getting linter errors. It would be cool if the no-unexpected-multiline rule could be either disabled or configured to not trigger in the cases that Prettier creates.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:28
  • Comments:5

github_iconTop GitHub Comments

4reactions
Hermanyacommented, May 31, 2019

this is crazy annoying, one kind of a workaround I found so far is replacing this

export const Checkbox = styled.input<
  React.HTMLAttributes<HTMLInputElement> & SpaceProps
>``

with this

type Props = React.HTMLAttributes<HTMLInputElement> & SpaceProps;
export const Checkbox = styled.input<Props>``
0reactions
stefatkinscommented, Sep 3, 2019

I added this to my package.json (i’m using typescript)

"eslintConfig": {
    "extends": "react-app",
    "overrides": [
      {
        "files": [
          "**/*.ts?(x)"
        ],
        "rules": {
          "no-unexpected-multiline": 0
        }
      }
    ]
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

prettier conflicts with no-unexpected-multiline #32 - GitHub
This scenario is relevant when a shareable config like airbnb-base is combined with prettier. If the rule no-unexpected-multiline is enabled ...
Read more >
Rationale - Prettier
Once an object literal becomes multiline, Prettier won't collapse it back. If in Prettier-formatted code, we add a property to an object literal,...
Read more >
no-unexpected-multiline - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint-config-prettier/README.md - UNPKG
Turns off all rules that are unnecessary or might conflict with [Prettier]. 4. 5, This lets you use you favorite shareable config without...
Read more >
Why does it seem like eslint and prettier are fighting one ...
As I worked on this project, I had rules that I wanted to turn off; mainly eslint no-unexpected-multiline , prettier printWidth and some ......
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