GithubHelp home page GithubHelp logo

standard / eslint-config-standard-react Goto Github PK

View Code? Open in Web Editor NEW
456.0 11.0 89.0 82 KB

ESLint Shareable Config for React/JSX support in JavaScript Standard Style

Home Page: https://standardjs.com

License: MIT License

JavaScript 100.00%
development ecmascript eslint es6 javascript linter standard static-code-analysis style-guide nodejs

eslint-config-standard-react's Introduction

Standard - JavaScript Style Guide
JavaScript Standard Style

discord External tests Internal tests status badge old Node test npm version npm downloads Standard - JavaScript Style Guide

Sponsored by    Socket – Supply Chain Dependency Security for JavaScript and npm    Wormhole

EnglishEspañol (Latinoamérica)FrançaisBahasa IndonesiaItaliano (Italian)日本語 (Japanese)한국어 (Korean)Português (Brasil)简体中文 (Simplified Chinese)繁體中文 (Taiwanese Mandarin)

JavaScript style guide, linter, and formatter

This module saves you (and others!) time in three ways:

  • No configuration. The easiest way to enforce code quality in your project. No decisions to make. No .eslintrc files to manage. It just works.
  • Automatically format code. Just run standard --fix and say goodbye to messy or inconsistent code.
  • Catch style issues & programmer errors early. Save precious code review time by eliminating back-and-forth between reviewer & contributor.

Give it a try by running npx standard --fix right now!

Table of Contents

Install

The easiest way to use JavaScript Standard Style is to install it globally as a Node command line program. Run the following command in Terminal:

$ npm install standard --global

Or, you can install standard locally, for use in a single project:

$ npm install standard --save-dev

Note: To run the preceding commands, Node.js and npm must be installed.

Usage

After you've installed standard, you should be able to use the standard program. The simplest use case would be checking the style of all JavaScript files in the current working directory:

$ standard
Error: Use JavaScript Standard Style
  lib/torrent.js:950:11: Expected '===' and instead saw '=='.

If you've installed standard locally, run with npx instead:

$ npx standard

You can optionally pass in a directory (or directories) using the glob pattern. Be sure to quote paths containing glob patterns so that they are expanded by standard instead of your shell:

$ standard "src/util/**/*.js" "test/**/*.js"

Note: by default standard will look for all files matching the patterns: **/*.js, **/*.jsx.

What you might do if you're clever

  1. Add it to package.json

    {
      "name": "my-cool-package",
      "devDependencies": {
        "standard": "*"
      },
      "scripts": {
        "test": "standard && node my-tests.js"
      }
    }
  2. Style is checked automatically when you run npm test

    $ npm test
    Error: Use JavaScript Standard Style
      lib/torrent.js:950:11: Expected '===' and instead saw '=='.
  3. Never give style feedback on a pull request again!

Why should I use JavaScript Standard Style?

The beauty of JavaScript Standard Style is that it's simple. No one wants to maintain multiple hundred-line style configuration files for every module/project they work on. Enough of this madness!

This module saves you (and others!) time in three ways:

  • No configuration. The easiest way to enforce consistent style in your project. Just drop it in.
  • Automatically format code. Just run standard --fix and say goodbye to messy or inconsistent code.
  • Catch style issues & programmer errors early. Save precious code review time by eliminating back-and-forth between reviewer & contributor.

Adopting standard style means ranking the importance of code clarity and community conventions higher than personal style. This might not make sense for 100% of projects and development cultures, however open source can be a hostile place for newbies. Setting up clear, automated contributor expectations makes a project healthier.

For more info, see the conference talk "Write Perfect Code with Standard and ESLint". In this talk, you'll learn about linting, when to use standard versus eslint, and how prettier compares to standard.

Who uses JavaScript Standard Style?

Free MIDIs, MIDI file downloads College essays, AP notes
Your Logo Here

In addition to companies, many community members use standard on packages that are too numerous to list here.

standard is also the top-starred linter in GitHub's Clean Code Linter showcase.

Are there text editor plugins?

First, install standard. Then, install the appropriate plugin for your editor:

Sublime Text

Using Package Control, install SublimeLinter and SublimeLinter-contrib-standard.

For automatic formatting on save, install StandardFormat.

Atom

Install linter-js-standard.

Alternatively, you can install linter-js-standard-engine. Instead of bundling a version of standard it will automatically use the version installed in your current project. It will also work out of the box with other linters based on standard-engine.

For automatic formatting, install standard-formatter. For snippets, install standardjs-snippets.

Visual Studio Code

Install vscode-standard. (Includes support for automatic formatting.)

For JS snippets, install: vscode-standardjs-snippets. For React snippets, install vscode-react-standard.

Vim

Install ale. And add these lines to your .vimrc file.

let g:ale_linters = {
\   'javascript': ['standard'],
\}
let g:ale_fixers = {'javascript': ['standard']}

This sets standard as your only linter and fixer for javascript files and so prevents conflicts with eslint. For linting and automatic fixing on save, add these lines to .vimrc:

let g:ale_lint_on_save = 1
let g:ale_fix_on_save = 1

Alternative plugins to consider include neomake and syntastic, both of which have built-in support for standard (though configuration may be necessary).

Emacs

Install Flycheck and check out the manual to learn how to enable it in your projects.

Brackets

Search the extension registry for "Standard Code Style" and click "Install".

WebStorm (PhpStorm, IntelliJ, RubyMine, JetBrains, etc.)

WebStorm recently announced native support for standard directly in the IDE.

If you still prefer to configure standard manually, follow this guide. This applies to all JetBrains products, including PhpStorm, IntelliJ, RubyMine, etc.

Is there a readme badge?

Yes! If you use standard in your project, you can include one of these badges in your readme to let people know that your code is using the standard style.

JavaScript Style Guide

[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)

JavaScript Style Guide

[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

I disagree with rule X, can you change it?

No. The whole point of standard is to save you time by avoiding bikeshedding about code style. There are lots of debates online about tabs vs. spaces, etc. that will never be resolved. These debates just distract from getting stuff done. At the end of the day you have to 'just pick something', and that's the whole philosophy of standard -- its a bunch of sensible 'just pick something' opinions. Hopefully, users see the value in that over defending their own opinions.

There are a couple of similar packages for anyone who does not want to completely accept standard:

If you really want to configure hundreds of ESLint rules individually, you can always use eslint directly with eslint-config-standard to layer your changes on top. standard-eject can help you migrate from standard to eslint and eslint-config-standard.

Pro tip: Just use standard and move on. There are actual real problems that you could spend your time solving! :P

But this isn't a real web standard!

Of course it's not! The style laid out here is not affiliated with any official web standards groups, which is why this repo is called standard/standard and not ECMA/standard.

The word "standard" has more meanings than just "web standard" :-) For example:

  • This module helps hold our code to a high standard of quality.
  • This module ensures that new contributors follow some basic style standards.

Is there an automatic formatter?

Yes! You can use standard --fix to fix most issues automatically.

standard --fix is built into standard for maximum convenience. Most problems are fixable, but some errors (like forgetting to handle errors) must be fixed manually.

To save you time, standard outputs the message "Run standard --fix to automatically fix some problems" when it detects problems that can be fixed automatically.

How do I ignore files?

Certain paths (node_modules/, coverage/, vendor/, *.min.js, and files/folders that begin with . like .git/) are automatically ignored.

Paths in a project's root .gitignore file are also automatically ignored.

Sometimes you need to ignore additional folders or specific minified files. To do that, add a standard.ignore property to package.json:

"standard": {
  "ignore": [
    "**/out/",
    "/lib/select2/",
    "/lib/ckeditor/",
    "tmp.js"
  ]
}

How do I disable a rule?

In rare cases, you'll need to break a rule and hide the error generated by standard.

JavaScript Standard Style uses ESLint under-the-hood and you can hide errors as you normally would if you used ESLint directly.

Disable all rules on a specific line:

file = 'I know what I am doing' // eslint-disable-line

Or, disable only the "no-use-before-define" rule:

file = 'I know what I am doing' // eslint-disable-line no-use-before-define

Or, disable the "no-use-before-define" rule for multiple lines:

/* eslint-disable no-use-before-define */
console.log('offending code goes here...')
console.log('offending code goes here...')
console.log('offending code goes here...')
/* eslint-enable no-use-before-define */

I use a library that pollutes the global namespace. How do I prevent "variable is not defined" errors?

Some packages (e.g. mocha) put their functions (e.g. describe, it) on the global object (poor form!). Since these functions are not defined or require'd anywhere in your code, standard will warn that you're using a variable that is not defined (usually, this rule is really useful for catching typos!). But we want to disable it for these global variables.

To let standard (as well as humans reading your code) know that certain variables are global in your code, add this to the top of your file:

/* global myVar1, myVar2 */

If you have hundreds of files, it may be desirable to avoid adding comments to every file. In this case, run:

$ standard --global myVar1 --global myVar2

Or, add this to package.json:

{
  "standard": {
    "globals": [ "myVar1", "myVar2" ]
  }
}

Note: global and globals are equivalent.

How do I use experimental JavaScript (ES Next) features?

standard supports the latest ECMAScript features, ES8 (ES2017), including language feature proposals that are in "Stage 4" of the proposal process.

To support experimental language features, standard supports specifying a custom JavaScript parser. Before using a custom parser, consider whether the added complexity is worth it.

To use a custom parser, first install it from npm:

npm install @babel/eslint-parser --save-dev

Then run:

$ standard --parser @babel/eslint-parser

Or, add this to package.json:

{
  "standard": {
    "parser": "@babel/eslint-parser"
  }
}

Can I use a JavaScript language variant, like Flow or TypeScript?

standard supports the latest ECMAScript features. However, Flow and TypeScript add new syntax to the language, so they are not supported out-of-the-box.

For TypeScript, an official variant ts-standard is supported and maintained that provides a very similar experience to standard.

For other JavaScript language variants, standard supports specifying a custom JavaScript parser as well as an ESLint plugin to handle the changed syntax. Before using a JavaScript language variant, consider whether the added complexity is worth it.

TypeScript

ts-standard is the officially supported variant for TypeScript. ts-standard supports all the same rules and options as standard and includes additional TypeScript specific rules. ts-standard will even lint regular javascript files by setting the configuration in tsconfig.json.

npm install ts-standard --save-dev

Then run (where tsconfig.json is located in the working directory):

$ ts-standard

Or, add this to package.json:

{
  "ts-standard": {
    "project": "./tsconfig.json"
  }
}

Note: To include additional files in linting such as test files, create a tsconfig.eslint.json file to use instead.

If you really want to configure hundreds of ESLint rules individually, you can always use eslint directly with eslint-config-standard-with-typescript to layer your changes on top.

Flow

To use Flow, you need to run standard with @babel/eslint-parser as the parser and eslint-plugin-flowtype as a plugin.

npm install @babel/eslint-parser eslint-plugin-flowtype --save-dev

Then run:

$ standard --parser @babel/eslint-parser --plugin flowtype

Or, add this to package.json:

{
  "standard": {
    "parser": "@babel/eslint-parser",
    "plugins": [ "flowtype" ]
  }
}

Note: plugin and plugins are equivalent.

What about Mocha, Jest, Jasmine, QUnit, etc?

To support mocha in test files, add this to the top of the test files:

/* eslint-env mocha */

Or, run:

$ standard --env mocha

Where mocha can be one of jest, jasmine, qunit, phantomjs, and so on. To see a full list, check ESLint's specifying environments documentation. For a list of what globals are available for these environments, check the globals npm module.

Note: env and envs are equivalent.

What about Web Workers and Service Workers?

Add this to the top of web worker files:

/* eslint-env worker */

This lets standard (as well as humans reading the code) know that self is a global in web worker code.

For Service workers, add this instead:

/* eslint-env serviceworker */

What is the difference between warnings and errors?

standard treats all rule violations as errors, which means that standard will exit with a non-zero (error) exit code.

However, we may occasionally release a new major version of standard which changes a rule that affects the majority of standard users (for example, transitioning from var to let/const). We do this only when we think the advantage is worth the cost and only when the rule is auto-fixable.

In these situations, we have a "transition period" where the rule change is only a "warning". Warnings don't cause standard to return a non-zero (error) exit code. However, a warning message will still print to the console. During the transition period, using standard --fix will update your code so that it's ready for the next major version.

The slow and careful approach is what we strive for with standard. We're generally extremely conservative in enforcing the usage of new language features. We want using standard to be light and fun and so we're careful about making changes that may get in your way. As always, you can disable a rule at any time, if necessary.

Can I check code inside of Markdown or HTML files?

To check code inside Markdown files, use standard-markdown.

Alternatively, there are ESLint plugins that can check code inside Markdown, HTML, and many other types of language files:

To check code inside Markdown files, use an ESLint plugin:

$ npm install eslint-plugin-markdown

Then, to check JS that appears inside code blocks, run:

$ standard --plugin markdown '**/*.md'

To check code inside HTML files, use an ESLint plugin:

$ npm install eslint-plugin-html

Then, to check JS that appears inside <script> tags, run:

$ standard --plugin html '**/*.html'

Is there a Git pre-commit hook?

Yes! Hooks are great for ensuring that unstyled code never even makes it into your repo. Never give style feedback on a pull request again!

You even have a choice...

Install your own hook

#!/bin/bash

# Ensure all JavaScript files staged for commit pass standard code style
function xargs-r() {
  # Portable version of "xargs -r". The -r flag is a GNU extension that
  # prevents xargs from running if there are no input files.
  if IFS= read -r -d $'\n' path; then
    echo "$path" | cat - | xargs "$@"
  fi
}
git diff --name-only --cached --relative | grep '\.jsx\?$' | sed 's/[^[:alnum:]]/\\&/g' | xargs-r -E '' -t standard
if [[ $? -ne 0 ]]; then
  echo 'JavaScript Standard Style errors were detected. Aborting commit.'
  exit 1
fi

Use a pre-commit hook

The pre-commit library allows hooks to be declared within a .pre-commit-config.yaml configuration file in the repo, and therefore more easily maintained across a team.

Users of pre-commit can simply add standard to their .pre-commit-config.yaml file, which will automatically fix .js, .jsx, .mjs and .cjs files:

  - repo: https://github.com/standard/standard
    rev: master
    hooks:
      - id: standard

Alternatively, for more advanced styling configurations, use standard within the eslint hook:

  - repo: https://github.com/pre-commit/mirrors-eslint
    rev: master
    hooks:
      - id: eslint
        files: \.[jt]sx?$  # *.js, *.jsx, *.ts and *.tsx
        types: [file]
        additional_dependencies:
          - eslint@latest
          - eslint-config-standard@latest
          # and whatever other plugins...

How do I make the output all colorful and pretty?

The built-in output is simple and straightforward, but if you like shiny things, install snazzy:

$ npm install snazzy

And run:

$ standard | snazzy

There's also standard-tap, standard-json, standard-reporter, and standard-summary.

Is there a Node.js API?

Yes!

async standard.lintText(text, [opts])

Lint the provided source text. An opts object may be provided:

{
  // unique to lintText
  filename: '',         // path of file containing the text being linted

  // common to lintText and lintFiles
  cwd: '',              // current working directory (default: process.cwd())
  fix: false,           // automatically fix problems
  extensions: [],       // file extensions to lint (has sane defaults)
  globals: [],          // custom global variables to declare
  plugins: [],          // custom eslint plugins
  envs: [],             // custom eslint environment
  parser: '',           // custom js parser (e.g. babel-eslint)
  usePackageJson: true, // use options from nearest package.json?
  useGitIgnore: true    // use file ignore patterns from .gitignore?
}

All options are optional, though some ESLint plugins require the filename option.

Additional options may be loaded from a package.json if it's found for the current working directory. See below for further details.

Returns a Promise resolving to the results or rejected with an Error.

The results object will contain the following properties:

const results = {
  results: [
    {
      filePath: '',
      messages: [
        { ruleId: '', message: '', line: 0, column: 0 }
      ],
      errorCount: 0,
      warningCount: 0,
      output: '' // fixed source code (only present with {fix: true} option)
    }
  ],
  errorCount: 0,
  warningCount: 0
}

async standard.lintFiles(files, [opts])

Lint the provided files globs. An opts object may be provided:

{
  // unique to lintFiles
  ignore: [],           // file globs to ignore (has sane defaults)

  // common to lintText and lintFiles
  cwd: '',              // current working directory (default: process.cwd())
  fix: false,           // automatically fix problems
  extensions: [],       // file extensions to lint (has sane defaults)
  globals: [],          // custom global variables to declare
  plugins: [],          // custom eslint plugins
  envs: [],             // custom eslint environment
  parser: '',           // custom js parser (e.g. babel-eslint)
  usePackageJson: true, // use options from nearest package.json?
  useGitIgnore: true    // use file ignore patterns from .gitignore?
}

Additional options may be loaded from a package.json if it's found for the current working directory. See below for further details.

Both ignore and files patterns are resolved relative to the current working directory.

Returns a Promise resolving to the results or rejected with an Error (same as above).

How do I contribute to StandardJS?

Contributions are welcome! Check out the issues or the PRs, and make your own if you want something that you don't see there.

Want to chat? Join contributors on Discord.

Here are some important packages in the standard ecosystem:

There are also many editor plugins, a list of npm packages that use standard, and an awesome list of packages in the standard ecosystem.

Security Policies and Procedures

The standard team and community take all security bugs in standard seriously. Please see our security policies and procedures document to learn how to report issues.

License

MIT. Copyright (c) Feross Aboukhadijeh.

eslint-config-standard-react's People

Contributors

alekseykulikov avatar barroudjo avatar blgm avatar btholt avatar chsdwn avatar danyshaanan avatar dcousens avatar dignifiedquire avatar donovanhiland avatar dtinth avatar ematipico avatar exarus avatar feross avatar greenkeeper[bot] avatar henrikjoreteg avatar jackytck avatar kid avatar kidkarolis avatar kigawas avatar kkoukiou avatar linusu avatar mightyiam avatar robinpokorny avatar rostislav-simonik avatar rstacruz avatar simonkberg avatar voxpelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-config-standard-react's Issues

Property Type Validation in React.js Stateless Functions?

[email protected]:

import cx from 'classnames'
import React from 'react'

export default function Button (props) {
  return (
    <button { ...props } type='button' className={ cx('cool-button', props.className) }>
      { props.children }
    </button>
  )
}

Returns error:

'className' is missing in props validation (react/prop-types)
'children' is missing in props validation (react/prop-types)

Rename props to prop and no error. AFAIK, you can't even do property type validation in React stateless functions.

More importantly, is standard forcing React.js property type validation even worth it? Honestly, I despise using ES6 classes with React because I feel like I gotta add a lot of boilerplate (property type validation) just to make standard happy. In the beginning, I felt like it was worth it, now I'm not so sure.

Thoughts on property type validation @feross @dcousens?

An in-range update of eslint-plugin-react is breaking the build 🚨

The devDependency eslint-plugin-react was updated from 7.14.0 to 7.14.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-react is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v7.14.1

Fixed

  • Fix prop-types crash on multiple destructuring (#2319 @golopot)
Commits

The new version differs by 3 commits.

  • 62255af Update CHANGELOG and bump version
  • 655eb01 Merge pull request #2320 from golopot/issue-2319
  • 9639d82 [Fix] prop-types: fix crash on multiple destructuring

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

props validation for stateless components

For a sateless component that looks like this:

const statelessComponent = (props) => {
  const subRender = () => {
    return <span>{props.someProp}</span>;
  };

  return <div>{subRender()}</div>;
};

statelessComponent.propTypes = {
  someProp: PropTypes.string
};

eslint throws:

'someProp' is missing in props validation

Which is odd, because someProp is definitely in propTypes. A work-around to satisfy the linter is to store the prop in a variable outside subRender the function:

const statelessComponent = (props) => {
  const someProp = props.someProp;

  const subRender = () => {
    return <span>{someProp}</span>;
  };

  return <div>{subRender()}</div>;
};

statelessComponent.propTypes = {
  someProp: PropTypes.string
};

I think this is either a bug in how the linter is checking for prop types, or, if the latter example is a preferred style, the message should be clearer about what's wrong here.

Definition for rule 'react/jsx-indent' was not found

I'm getting a project linting error "Definition for rule 'react/jsx-indent' was not found" using version 2.0.0. Using 1.2.1 doesn't give me any issue.

Also seeing "Parsing error: Unexpected token <" in any file containing tags. Again, only with 2.0.0.

Unexpected error comes out when everything is ok

This is ok and no error comes out.

    return (
      <p>
        I'm {this.state.name}
      </p>
    )

when I add any character after this like:

    return (
      <p>
        I'm {this.state.name} any string here
      </p>
    )

and the error comes out:

Expected indentation of 8 space characters but found 1. (react/jsx-indent)

my eslint config :

module.exports = {
  root: true,
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  env: {
    es6: true,
    commonjs: true,
    browser: true,
  },
  extends: [
      'standard',
      'standard-react'
  ],
  plugins: [
    'react',
    'babel',
    'promise'
  ],
  'rules': {
    'arrow-parens': 0,
    'generator-star-spacing': 0,
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
  }
}

Is it a bug or something wrong with my config?

Indent error: expected indentation of 2 space characters but found 4

Hi, I am using this linter standard within a project, and I got this error with this code here:

https://github.com/alayek/Markpad/blob/devel/src/components/AppNavBar.js#L6

In this line, it says

error Expected indentation of 2 space characters but found 4

Is this an issue with the linter, or are we doing something wrong? I would normally ask in some forum or chat channel; but I couldn't find anything like that.

Thanks in advance.

DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead.

(node:36737) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "standard-react")
(node:36737) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "node_modules/eslint-config-standard-jsx/index.js")
(node:36737) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "standard")

"TypeError: path.charAt is not a function"

Since eslint/eslint#2711 isn't in a tagged release yet, if your .eslintrc file has:

{
  "extends": ["standard", "standard-react"]
}

It'll throw TypeError: path.charAt is not a function.

It looks like standard is using a hardcoded eslint: https://github.com/feross/standard/blob/22e640da289a6d30e631bacbd85037ba33d776de/package.json

For people that wanna use this on its own, you'll need to install the hard-coded version of eslint until there's a new tagged release.

Maybe it's a good idea to add a temporary note to the README?

missing in props validation

I'm using the standard command and the atom linter and for the code below it's stating 'url' is missing in props validation. Do I have to switch to eslint and config files? I'd really like to be able to use standard and the atom linter.

var Layout = require('./layout.jsx')
var React = require('react')

module.exports = React.createClass({
  render: function render () {
    return (
    <Layout {...this.props}>
      <h3>URL: {this.props.url} - Not Found(404)</h3>
      <h6>I am a Plain vanilla react view</h6>
    </Layout>
    )
  }
})

No unused variables for stateless functional components

I would expect the code below to warn me about the fact that bar is not used.

I was trying out xo the other day and it does give that warning. It is also based on eslint-plugin-react, so I'm wonder if it's just a difference in settings...

import {PropTypes} from 'react'

Foo.propTypes = {bla: PropTypes.string}

export default function Foo ({bar}) {
  return <div/>
}

no-did-update-set-state should not throw an error since React 16.4

Since componentWillReceiveProps has been deprecated, componentDidUpdate has to be used to detect changes in props and set state accordingly (the other option being using getDerivedStateFromProps AND polluting the state with old props just to track changes).

However I realise this is a bit tricky as it depends on the version of React...

The Curious Case of the Dangling Comma

I'm interested in using your library, and though I know it's not up for debate, I do seek a footnote on your reasoning to keep the comma-dangle rule in standard-react.

I know IE 8 is the culprit and I'm not even going to debate the scarcity of such a terrible browser.

What I'm interested in, is would you consider at the very least, creating a version of standard-react that is primarily for react-native. A safe place, where IE 8 can never go, and the friendliness of ECMA Script 5's dangling comma can come out and join the land of good ideas.

Poetic/Comma Deprived license aside, I'm interested in your feedback and thoughts on making Standard available for best practices in React Native.

Fails to do stuff

I like to consider myself an advanced user. I installed this because it was mentioned in the standard docs and because I'm trying to make some React magic disappear from my linters. But after following the usage instructions, touching and configuring the lint config file and running this, absolutely nothing changes in my output. Which begs the question. Why does this even exist?

npm -v && node -v
3.10.3
v6.3.1

Unmet peer dependency when installing a fresh create-react-app application

Trying to set up eslint-config-standard on freshly created react app with create-react-app, I get these unmet peer dependencies.

create-react-app version:

$ create-react-app -V
1.4.1

react-scripts version (package.json):
"react-scripts": "1.0.14"

react version (package.json):

    "react": "^16.0.0",
    "react-dom": "^16.0.0",

yarn command and output:

$ yarn add --dev eslint-config-standard eslint-config-standard-react eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node eslint-plugin-react
yarn add v1.2.1
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
warning Pattern ["eslint-plugin-import@^2.7.0"] is trying to unpack in the same destination "/Library/Caches/Yarn/v1/npm-eslint-plugin-import-2.7.0-21de33380b9efb55f5ef6d2e210ec0e07e7fa69f" as pattern ["[email protected]"]. This could result in a non deterministic behavior, skipping.
[3/4] 🔗  Linking dependencies...
warning "[email protected]" has unmet peer dependency "eslint@>=3.19.0".
warning "[email protected]" has unmet peer dependency "eslint@>=3.19.0".
warning "[email protected]" has unmet peer dependency "eslint@>=3.19.0".
warning "[email protected]" has unmet peer dependency "eslint@>=3.19.0".
warning "[email protected]" has unmet peer dependency "[email protected] - 4.x".
warning "[email protected]" has unmet peer dependency "eslint@>=3.1.0".
warning "[email protected]" has unmet peer dependency "eslint@^3.0.0 || ^4.0.0".
[4/4] 📃  Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.

Regards.

How to use?

Dump question here:

I already have standard in my project, it works perfectly.
I have done the setup in readme.md to configure some rules for React, but this doesn't work.

What do I have to do?
I am calling the standard (yarn standard) in the same way that before.

Make work with install-peerdeps

This is what every other eslint config is migrating to.

So instead of npm i -D eslint-config-standard eslint-config-standard-react eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node eslint-plugin-react

You just have to put all that stuff in peerDependencies then users can just do $ install-peerdeps eslint-config-standard-react

Happy to PR this if you'd like?

Using stateless function through function invoking way hints me missing props validation.

When using stateless function through function invoking, React doesn't validate the props' type, but rule react/prop-types hints you write component's propTypes. It doesn't make sense.

const renderHello = ({ name }) => (
    <h1>Hello {name}</h1>
)

// It doesn't work at all, so you can define the prop name to any types. If you missed it eslint will hint you missing props validator.
renderHello.propTypes = {
  name: PropTypes.func
}

const App = () => (
  <div>{renderHello({ name: 'world' })}</div>
)

This way, its imperative to write propTypes.

const Hello = ({ name }) => (
    <h1>Hello {name}</h1>
)

Hello.propTypes = {
  name: PropTypes.string
}

const App = () => (
  <div><Hello name={'world'} /></div>
)

Consider new rules from eslint-plugin-react@3

eslint-plugin-react v3 was released. I wanted to make sure you react folks (@dcousens, @cesarandreu, @jprichardson, @dcposch) knew about it.

If there are any rule changes you want to make, please go ahead. standard v5 will be upgrading the eslint-plugin-react dependency from v2 to v3.

This is their changelog:
#3.1.0 / 2015-07-28

  • update dependencies
  • add event handlers to no-unknown-property (#164 @MKenyon)
  • add customValidators option to prop-types (#145 @CalebMorris)
  • fix comment handling in jsx-curly-spacing (#165)
  • documentation improvements (#167 @ngbrown)
    #3.0.0 / 2015-07-21
  • add jsx-no-duplicate-props rule (#161 @hummlas)
  • add allowMultiline option to the jsx-curly-spacing rule (#156 @mathieumg)
  • breaking in jsx-curly-spacing braces spanning multiple lines are now allowed with never option (#156 @mathieumg)
  • fix multiple var and destructuring handling in props-types (#159)
  • fix crash when retrieving propType name (#163)

Incompatibility with latest eslint

I cannot install eslint-config-standard-react when using latest eslint (v8.11.0).

What version of this package are you using?

None.

What operating system, Node.js, and npm version?

node v16.14.1
npm v8.5.0

What happened?

☹ npm install eslint-config-standard-react
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/eslint
npm ERR!   dev eslint@"^8.11.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^7.12.1" from [email protected]
npm ERR! node_modules/eslint-config-standard-react
npm ERR!   eslint-config-standard-react@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/xxx/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2022-03-17T13_08_25_292Z-debug-0.log


☹ npm install eslint-config-standard-react@next                                                                                                                                 
npm ERR! code ETARGET
npm ERR! notarget No matching version found for eslint-config-standard-react@next.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2022-03-17T13_08_41_872Z-debug-0.log

What did you expect to happen?

Package being installed/added to package.json.

Are you willing to submit a pull request to fix this bug?

I don't feel competent enough.

modify rule jsx-no-bind

commit : d2352bd
I saw in this commit that you modified this rule :

"react/jsx-no-bind": 2

for this :

 "react/jsx-no-bind": [2, {
     "allowArrowFunctions": true,
     "allowBind": false,
     "ignoreRefs": true
 }]

Is this intentional or is it just a mistake ?

As far as i know, using arrow functions in render is still an anti-pattern :
https://medium.com/@esamatti/react-js-pure-render-performance-anti-pattern-fb88c101332f#.hz1kmeu4g
https://medium.com/@machnicki/handle-events-in-react-with-arrow-functions-ede88184bbb#.oo0nompik

Thus, in my opinion, the rule should be :

 "react/jsx-no-bind": [2, {
     "allowArrowFunctions": false,
     "allowBind": false,
     "ignoreRefs": false
 }]

which is equivalent to

"react/jsx-no-bind": 2

Adding React Hooks rules

Hey there, is it still the plan to add the React Hooks rules to Standard as discussed in #63? This would be super useful. Thanks :)

Unable to install

Unfortunately I am not able to install the package

`C:\malo\www\_Frontend>npm install eslint-config-standard --save-dev
npm WARN peerDependencies The peer dependency eslint@^2.0.0-rc.0 included from eslint-config-standard will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "eslint-config-standard" "--save-dev"
npm ERR! node v4.3.0
npm ERR! npm  v2.14.12
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants eslint@^2.0.0-rc.0
npm ERR! peerinvalid Peer [email protected] wants eslint@^1.6.0
npm ERR! peerinvalid Peer [email protected] wants eslint@^2.0.0-rc.0

npm ERR! Please include the following file with any support request:
npm ERR!     C:\malo\www\_Frontend\npm-debug.log`

What should I do to make it works?

error using Class Properties with React

state = {
    collapse: false
}

The error occurs, when I put the state like show above using class properties, says that the equal sign (=) is an unexpected token. 🙁

captura de pantalla 2018-03-17 a la s 15 42 45

Error - .eslintrc.js » eslint-config-standard-react

What version of this package are you using?
"eslint": "^6.6.0",
"eslint-config-standard-react": "^9.2.0",

What operating system, Node.js, and npm version?
node: v12.8.0
yarn: 1.17.3

What happened?

[Error - 6:03:17 PM] .eslintrc.js » eslint-config-standard-react » /Users/vedmant/Projects/_My/MY-10 RunningTimeApp/RunningTimeRN/node_modules/eslint-config-standard-jsx/index.js: Configuration for rule "react/jsx-indent" is invalid: Value {"checkAttributes":true,"indentLogicalExpressions":true} should NOT have additional properties.

What did you expect to happen?

No error

Are you willing to submit a pull request to fix this bug?

No

Add rule react/no-unused-prop-types

What about to add this useful rule to defaults?

import React, { PropTypes } from 'react'

function Foo ({
  bar
}) {
  return (
    <div>{bar}</div>
  )
}

Foo.propTypes = {
  className: PropTypes.string, // 'className' PropType is defined but prop is never used
  bar: PropTypes.string
}

export default Foo

Reintroduce react-in-jsx-scope rule

As per commit 263162f, react-in-jsx-scope was removed from this config. If I understand the history of this project well, then at some point eslint-config-standard-jsx was created (after commit 263162f was applied) that contains rules that apply to JSX in general, and not specifically React.

If the aim of this project is to protect against specific React errors, then this rule should be reintroduced because a React component will fail at runtime, when React is not in scope when using JSX.

Question: why is react/wrap-multilines = 2?

This is considered ok:

let Hello = React.createClass({
  render () {
    return (
      <div>
        <p>Hello {this.props.name}</p>
      </div>
    )
  }
})

But this isn't:

let Hello = React.createClass({
  render () {
    return <div>
      <p>Hello {this.props.name}</p>
    </div>
  }
})

Just wondering, what's the rationale behind this decision?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.