Skip to content

React Airbnb Styleguide setup #147

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

Closed
bitsmyth opened this issue Jan 26, 2019 · 7 comments
Closed

React Airbnb Styleguide setup #147

bitsmyth opened this issue Jan 26, 2019 · 7 comments
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@bitsmyth
Copy link

bitsmyth commented Jan 26, 2019

I would like to know if it is possible to have a react / react-native typescript project with eslint and airbnb-react styleguide by using this lib?

@bitsmyth bitsmyth added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 26, 2019
@bradzacher bradzacher added question Questions! (i.e. not a bug / enhancment / documentation) and removed triage Waiting for team members to take a look labels Jan 27, 2019
@bradzacher
Copy link
Member

Install the dependencies

yarn add -D eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-react @typescript-eslint/parser @typescript-eslint/eslint-plugin 

Then you can simply use the recommended config if you like:

{
	"extends": ["airbnb", "plugin:@typescript-eslint/recommended"],
}

Otherwise, you can configure our plugin yourself:

{
	"extends": ["airbnb"],
    "parser": "@typescript-eslint/parser",
	"plugins": ["@typescript-eslint"],
	"rules": {
		"@typescript-eslint/rule-name": "error"
	}
}

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party documentation Documentation ("docs") that needs adding/updating and removed awaiting response Issues waiting for a reply from the OP or another party question Questions! (i.e. not a bug / enhancment / documentation) labels Jan 30, 2019
@bradzacher
Copy link
Member

It would probably be good for us to document this considering it is probably a very common use case.

@ldrick
Copy link
Contributor

ldrick commented Jan 30, 2019

Hi, I have a working airbnb + typescript + prettier .eslintrc.js, this might help you: eslint/eslint#8813 (comment)

@aboyton
Copy link
Contributor

aboyton commented Feb 1, 2019

I've added a PR that adds some instructions in #177. Feedback welcome.

To make it work on TSLint's codebase (you've got to try your instructions somewhere 😄) I had to disable no-useless-constructor, I'm guessing that this is due to #15.

  "rules": {
    "no-useless-constructor": "off"
  }

@bitsmyth
Copy link
Author

bitsmyth commented Feb 1, 2019

yarn add -D eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-react @typescript-eslint/parser @typescript-eslint/eslint-plugin 

Sadly this did not work. I run that command after reverting the suggested commands.

npm install eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-react @typescript-eslint/parser @typescript-eslint/eslint-plugin --save -dev

Then I had to install some peer dependencies

npm i -save -dev eslint-plugin-jsx-a11y@^6.1.1 acorn@^6.0.0

and extended .eslintrc.json with the suggestion

{
  "extends": ["airbnb", "plugin:@typescript-eslint/recommended"]
}

But the App.tsx does not get linted for airbnb styles. I setup VS-Code workspace settings with

  "eslint.enable": true,
  "prettier.eslintIntegration": true,
  "eslint.run": "onSave",

so after saving I can see that prettier is applying some airbnb rules. But the usual styleguide gets igonored. I tested it with react/jsx-no-bind from here

@deskoh
Copy link

deskoh commented Jul 21, 2019

@bradzacher I refer to the following configuration.

{
	"extends": ["airbnb", "plugin:@typescript-eslint/recommended"],
}

This is allowing rules in @typescript-eslint/recommended to take precedence? In particular indent, no-unused-vars and no-use-before-define rules in @typescript-eslint/recommended are not similar to the equivalent ESLint rules in airbnb.

For TypeScript variant of Airbnb, I concluded that it would not be as straightforward, which is what I'm trying to achieve in my repo.

@bradzacher
Copy link
Member

No, it does work that way, because the base rule indent is a completely separate rule to our rule @typescript-eslint/indent.
So eslint doesn't share the config between them.

In our recommended, we do switch off the base rules that conflict, and turn on our version

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/configs/recommended.json

however, note you'll lose airbnb's config for those rules, and it'll instead just use the default config for the rule.

jeremy2 added a commit to nitidbit/cra-ts-eslint-prettier that referenced this issue Oct 18, 2019
typescript-eslint/typescript-eslint#147
yarn add -D eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-react @typescript-eslint/parser @typescript-eslint/eslint-plugin
eslint --init
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

5 participants