How can I disable the error (prettier/prettier) on eslint?
Asked Answered
E

3

78

While coding, I was not using eslint. Now I installed it and it has flooded my editor with prettier/prettier errors, which by no way seem like they make my code prettier. I am looking to find a way to solve this.

prettierrc.js:

module.exports = {
  bracketSpacing: true,
  jsxBracketSameLine: false,
  singleQuote: true,
  trailingComma: 'all',
};

eslintrc.js:

module.exports = {
  root: true,
  extends: '@react-native-community',
};

And finally, some example code:

import React, {Component} from 'react';
import {View, Text, Picker} from 'react-native';
import {connect} from 'react-redux';
import {employeeUpdate} from '../actions';
import {CardSection,  Input} from './common';

class EmployeeForm extends Component {
  render(){
    return (
      <View>
      <CardSection>
        <Input
          label="Name"
          placeholder="Marco"
          value={this.props.name}
          onChangeText={value => this.props.employeeUpdate({prop: 'name', value})}
        />
      </CardSection>

      <CardSection>
        <Input
          label="Phone"
          placeholder="555-5555"
          value={this.props.phone}
          onChangeText={value => this.props.employeeUpdate({prop: 'phone', value })}
        />
      </CardSection>

      <CardSection style={{ flexDirection: 'row'}}>
        <Text style={styles.pickerTextStyle}>Shift</Text>
        <Picker
        style={{flex: 1}}
        selectedValue={this.props.shift}
        onValueChange={value => this.props.employeeUpdate({prop: 'shift', value})}
        >
          <Picker.Item label="Monday" value="Monday" />
          <Picker.Item label="Tuesday" value="Tuesday"/>
          <Picker.Item label="Wednesday" value="Wednesday"/>
          <Picker.Item label="Thursday" value="Thursday"/>
          <Picker.Item label="Friday" value="Friday"/>
          <Picker.Item label="Saturday" value="Saturday"/>
          <Picker.Item label="Sunday" value="Sunday"/>
        </Picker>
      </CardSection>
      </View>
    );
  }
}

I am simply trying to remove the error since it is annoying to have thousands of red dots looking to make my code "prettier", which is not achieving.

Eschalot answered 17/10, 2019 at 4:0 Comment(1)
prettier.io/docs/en/…Antechoir
P
219

Instead of disabling linting for the file, you can instead disable prettier within the eslintrc.js config file:

module.exports = {
  root: true,
  extends: '@react-native-community',
  rules: {
    'prettier/prettier': 0,
  },
};
Panathenaea answered 22/1, 2020 at 23:35 Comment(13)
You saved me hours of searching/config. IntelliJ IDEA wasn't fixing ESLint errors due to this. Thanks!Sussna
is there a way to just stop errors in compile time?Mistook
For my react-native project, this disables prettier indeed but not eslint yellow warningsFro
I can confirm this still works correctly with RN 0.66, so you may be seeing a different warning, or one come from another module. What rule is eslint returning warnings for?Panathenaea
This just saved me hours of hair pulling. I swear, excessive linting is going to turn me bald someday.Recommit
Glad to help! I really don't understand why they felt the need to make this default in the community package, when so many prefer not to use it.Panathenaea
Thirded! Already spent hours pulling hair and this comment finally saved the day! @PanathenaeaKelleykelli
@Fro did you get the solution? I don't like to add Semi-colons at the end of each line, but VS Code keeps highlighting these lines with yellow warnings.Nim
@MuhammadTahirAli In VSCode's Problem area it should tell you which eslint rule is causing the warning, and more than likely it's coming from the default semicolon rule. Just set "semicolon": [0, "never"] in your eslintrc rules.Panathenaea
Is there a way to set this property globally? It seems that I would have to do it for each project.Boccie
@Boccie yes, you could use a global eslint config for this rule.Panathenaea
can I disable some specific prettier rules as well from .eslintrc.json? Ex I just want to turn off trailing comma prettier rule @PanathenaeaLoera
@Loera I still don't think you can. You can find out more from the post here: https://mcmap.net/q/263295/-how-to-ignore-specific-rule-s-with-prettierPanathenaea
K
3

To get rid of conflicting rules when using both - prettier and eslint there is a eslint-config-prettier package.

Run npm install --save-dev eslint-config-prettier to install and then in eslintrc.js (or wherever you have the eslint rules defined) add:

{
  "extends": [
    ...,
    "@react-native-community",
    "prettier"
  ]
}

Now eslint should respect prettier rules. Here is a link to GH repo.

Kerrill answered 23/7, 2022 at 16:56 Comment(1)
I already had both packages but prettier was highlighting my vscode interface with errors - I dont need this as I have autofix on save which will fix everything without me even knowing that there were few unnecessary tabs. this was just annoying to see errors everywherePutscher
A
0

So I had both eslint-plugin-prettier and eslint-config-prettier on my package.json as devdependencies. I removed the eslint-config-prettier and it seemed to work for me.

//.eslintrc.js

module.exports = {
  root: true,
  extends: ['@react-native', 'prettier'],
  rules: {
    'react/react-in-jsx-scope': 'off',
    'react-native/no-inline-styles': 'off',
  },
};
Agency answered 10/1, 2024 at 4:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.