Giter Club home page Giter Club logo

eslint-config-airbnb-typescript's Introduction

eslint-config-airbnb-typescript

Version Downloads Last commit Build License PRs Welcome Code of conduct

Enhances Airbnb's ESLint config with TypeScript support

Setup

1) Setup regular Airbnb config

Make sure you have the regular Airbnb config setup. If you are using React, use eslint-config-airbnb, or if you aren't using React, use eslint-config-airbnb-base.

2) Install dependencies (and peer dependencies)

npm install eslint-config-airbnb-typescript \
            @typescript-eslint/eslint-plugin@^7.0.0 \
            @typescript-eslint/parser@^7.0.0 \
            --save-dev

3) Configure ESLint

Within your ESLint config file:

extends: [
  'airbnb',
+ 'airbnb-typescript'
]

If you don't need React support:

extends: [
  'airbnb-base',
+ 'airbnb-typescript/base'
]

4) Configure the ESLint TypeScript parser

This config requires knowledge of your TypeScript config.

In your ESLint config, set parserOptions.project to the path of your tsconfig.json.

For example:

{
  extends: ['airbnb', 'airbnb-typescript'],
+ parserOptions: {
+   project: './tsconfig.json'
+ }
}

5) Run ESLint

Open a terminal to the root of your project, and run the following command:

npx eslint . --ext .js,.jsx,.ts,.tsx

ESLint will lint all .js, .jsx, .ts, and .tsx files within the current folder, and output results to your terminal.

You can also get results in realtime inside most IDEs via a plugin.

FAQ

I get this error when running ESLint: "The file must be included in at least one of the projects provided"

This means you are attempting to lint a file that tsconfig.json doesn't include.

A common fix is to create a tsconfig.eslint.json file, which extends your tsconfig.json file and includes all files you are linting.

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "src/**/*.js", "test/**/*.ts"]
}

Update your ESLint config file:

parserOptions: {
-  project: './tsconfig.json',
+  project: './tsconfig.eslint.json',
}

Why do I need the peer dependencies?

@typescript-eslint/eslint-plugin is a peer dependency due to a limitation within ESLint. See issue, RFC, and progress.

@typescript-eslint/parser is a peer dependency because the version number must match @typescript-eslint/eslint-plugin.

I wish this config would support [...]

This config simply enhances the Airbnb with TypeScript support. It's not a single config to cater for all TypeScript linting requirements. For additional functionality, alter your ESLint config file. For example:

module.exports = {
  extends: [
    'airbnb',
    'airbnb-typescript',
    'airbnb/hooks',
    'plugin:@typescript-eslint/recommended-type-checked', // @typescript-eslint @v6
    'plugin:@typescript-eslint/stylistic-type-checked', // @typescript-eslint @v6
    // 'plugin:@typescript-eslint/recommended',                          // @typescript-eslint @v5
    // 'plugin:@typescript-eslint/recommended-requiring-type-checking',  // @typescript-eslint @v5
  ],
};

My personal ESLint config file with support for Jest, Promises, and Prettier can be found in create-exposed-app.

Why is import/no-unresolved disabled?

Two reasons:

  1. It requires additional configuration, which may be different for monorepo's, webpack usage, etc
  2. The rule offers little value in a TypeScript world, as the TypeScript compiler will catch these errors

If you would like to enable this rule, then:

Additional Documentation

Credits

Authored and maintained by Matt Turnbull (iamturns.com / @iamturns)

A big thank you to all contributors!

License

Open source licensed as MIT.

eslint-config-airbnb-typescript's People

Contributors

apust avatar chaitanyapotti avatar chomosuke avatar dartess avatar dependabot[bot] avatar deskoh avatar guilhermetod avatar hcharley avatar iamturns avatar jrolfs avatar jun-sheaf avatar kripod avatar lotap avatar lucasvazq avatar renovate[bot] avatar shpakkdv avatar snacqs avatar steven-g-w avatar tombell avatar zamiell 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

eslint-config-airbnb-typescript's Issues

unsupported typescript version

getting the following warning on typescript v3.7.2

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.6.0

YOUR TYPESCRIPT VERSION: 3.7.2

Please only submit bug reports when using the officially supported version.

here is my eslint config file

{
  "env": {
    "browser": true,
    "jest": true,
    "node": true,
    "es6": true
  },
  "extends": [
    "airbnb-typescript",
    "airbnb/hooks",
    "prettier",
    "prettier/@typescript-eslint",
    "prettier/react"
  ],
  "globals": {
    "window": true,
    "env": true
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module",
    "project": "./tsconfig.json"
  },
  "plugins": ["@typescript-eslint", "jsx-a11y", "prettier", "react-hooks"],
  "settings": {
    "import/resolver": {
      "typescript": {}
    },
    "import/ignore": [".js", ".jsx"]
  },
  "rules": {
    "class-methods-use-this": "off",
    "consistent-return": [
      "error",
      {
        "treatUndefinedAsUnspecified": true
      }
    ],
    "global-require": "off",
    "import/prefer-default-export": 0,
    "import/no-named-as-default": 0,
    "import/no-cycle": 0,
    "indent": 0,
    "one-var": 0,
    "one-var-declaration-per-line": 0,
    "no-alert": 0,
    "no-use-before-define": "off",
    "import/no-extraneous-dependencies": "off",
    "no-nested-ternary": "off",
    "no-shadow": 0,
    "no-underscore-dangle": 0,
    "no-unneeded-ternary": "off",
    "prefer-const": [2],
    "prettier/prettier": ["error"],
    "react/jsx-filename-extension": "off",
    "react/prop-types": "off",
    "react/jsx-indent": "off",
    "react/jsx-one-expression-per-line": "off",
    "react/jsx-wrap-multilines": "off",
    "react/destructuring-assignment": "off",
    "react/no-array-index-key": "off",
    "jsx-a11y/no-noninteractive-tabindex": [
      "error",
      {
        "roles": ["region"]
      }
    ],
    "space-before-function-paren": 0,
    "strict": 0,
    "trailing-comma": [
      "error",
      {
        "multiline": {
          "objects": "always",
          "arrays": "always"
        },
        "esSpecCompliant": true
      }
    ]
  }
}

TypeError: sourceCode.isSpaceBetween is not a function

Weird this is happening only when running eslint, no warnings or errors show up while editing the file. Looks like from the stack trace that its an isssue with @typescript-eslint/eslint-plugin comma spacing rule? Let me know if this is the wrong place for this ticket.

eslintrc:

module.exports = {
  extends: ["airbnb-typescript"],
  parserOptions: {
    project: './tsconfig.json'
  },
  rules: {
    "react/prop-types": 0,
    "@typescript-eslint/quotes": [
      "error",
      "double",
      {
        avoidEscape: true
      }
    ]
  },
  settings: {
    react: {
      version: "detect",
    }
  },
};

Error output

TypeError: sourceCode.isSpaceBetween is not a function
Occurred while linting somepath/src/charts/single-line/single-line.tsx:1
    at validateCommaSpacing (somepath/node_modules/@typescript-eslint/eslint-plugin/dist/rules/comma-spacing.js:87:44)
    at Program:exit.tokensAndComments.forEach (somepath/node_modules/@typescript-eslint/eslint-plugin/dist/rules/comma-spacing.js:131:21)
    at Array.forEach (<anonymous>)
    at Program:exit (somepath/node_modules/@typescript-eslint/eslint-plugin/dist/rules/comma-spacing.js:125:35)
    at listeners.(anonymous function).forEach.listener (/Users/Colini/.nvm/versions/node/v10.14.2/lib/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/Colini/.nvm/versions/node/v10.14.2/lib/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/Colini/.nvm/versions/node/v10.14.2/lib/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/Colini/.nvm/versions/node/v10.14.2/lib/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.leaveNode (/Users/Colini/.nvm/versions/node/v10.14.2/lib/node_modules/eslint/lib/linter/node-event-generator.js:306:14)

package.json

...
"devDependencies": {
    "@commitlint/cli": "^7.2.1",
    "@commitlint/config-conventional": "^8.3.4",
    "@storybook/addon-a11y": "^5.0.0",
    "@storybook/addon-actions": "^5.0.0",
    "@storybook/addon-links": "^5.0.0",
    "@storybook/addon-notes": "^5.0.0",
    "@storybook/addon-options": "^5.0.0",
    "@storybook/addons": "^5.0.0",
    "@storybook/cli": "^5.0.0",
    "@storybook/react": "^5.0.0",
    "@testing-library/jest-dom": "^4.0.0",
    "@testing-library/react": "^8.0.6",
    "@types/jest": "^24.0.9",
    "@types/node": "^11.10.4",
    "@types/ramda": "^0.25.42",
    "@types/react": "^16.7.13",
    "@types/react-dom": "^16.0.11",
    "@types/react-helmet": "^5.0.7",
    "@types/react-intl": "^2.3.14",
    "@types/react-redux": "^7.0.1",
    "@types/react-router-dom": "^5.1.3",
    "@types/recharts": "^1.1.4",
    "@types/reduce-reducers": "^0.3.0",
    "@types/storybook__react": "^4.0.0",
    "@types/styled-components": "^4.1.3",
    "@typescript-eslint/eslint-plugin": "^2.24.0",
    "ajv": "^6.6.1",
    "autoprefixer": "^9.4.2",
    "axios-mock-adapter": "^1.17.0",
    "babel-plugin-styled-components": "1.10.2",
    "boxen": "^3.0.0",
    "chalk": "^2.4.1",
    "commitizen": "^3.0.5",
    "cz-conventional-changelog": "^2.1.0",
    "docz": "^1.3.2",
    "docz-theme-default": "^1.2.0",
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.7.0",
    "eslint": "^6.8.0",
    "eslint-config-airbnb-typescript": "^7.2.0",
    "eslint-plugin-import": "^2.20.1",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^2.5.0",
    "execa": "^1.0.0",
    "husky": "^1.3.1",
    "hygen": "^4.0.9",
    "jest-enzyme": "^7.0.1",
    "jest-styled-components": "^6.3.1",
    "listr": "^0.14.3",
    "log-symbols": "^2.2.0",
    "mvy": "^0.1.0",
    "postcss-normalize": "^7.0.1",
    "react-app-rewire-postcss": "^3.0.2",
    "react-app-rewired": "^1.6.2",
    "react-router": "^5.1.0",
    "react-scripts": "2.1.0",
    "source-map-explorer": "^2.1.0",
    "storybook-react-router": "^1.0.2",
    "ts-jest": "^24.0.0",
    "ts-node": "8.4.0",
    "typescript": "^3.2.2",
    "xlsx": "^0.15.6"
  }

single-line.tsx

import React, { SFC, SVGProps } from "react";
import {
  LineChart,
  Line,
  XAxis,
  YAxis,
  CartesianGrid,
  ResponsiveContainer,
} from "recharts";
import { connect } from "react-redux";
import { ThemeInterface, styled } from "../../theme/util/helpers";
import {
  dividerColor,
  primaryAccentBackground,
} from "../../theme/theme/colors";
import { RootState } from "../../store/root";
import { themeSelector } from "../../theme/theme.selector";

export interface LineChartProps {
  theme: ThemeInterface;
  data: {
    xAxis: string | number;
    yAxis: string | number;
  }[];
  xAxis: string;
  yAxis: string;
}

const StyledChart = styled.div``;

interface AxisTickProps extends SVGProps<SVGElement> {
  payload: {
    coordinate: number;
    index: number;
    isShow: boolean;
    offset: number;
    tickCoord: number;
    value: string;
  };
}

const CustomizedAxisTick: SFC<AxisTickProps> = (props) => {
  const { x, y, payload } = props;

  return (
    <g transform={`translate(${x}, ${y})`}>
      <text
        x={0}
        y={0}
        dy={16}
        textAnchor="end"
        fill="currentColor"
        transform="rotate(-35)"
      >
        {payload.value}
      </text>
    </g>
  );
};

const Chart: SFC<LineChartProps> = (props) => {
  const { data, xAxis, yAxis } = props;
  const dividerColour = dividerColor(props);
  const backgroundColor = primaryAccentBackground(props);

  return (
    <StyledChart>
      <ResponsiveContainer width="99%" aspect={4 / 3}>
        <LineChart
          data={data}
          width={100}
          height={100}
          margin={{
            left: 10, top: 20, right: 50, bottom: 65,
          }}
        >
          <XAxis
            stroke="currentColor"
            dataKey="xAxis"
            name={xAxis}
            tickSize={10}
            axisLine={false}
            tickMargin={10}
            tick={CustomizedAxisTick}
            minTickGap={1}
          />

          <YAxis
            stroke="currentColor"
            dataKey="yAxis"
            name={yAxis}
            tickCount={10}
            axisLine={false}
            tickLine={false}
            tickMargin={10}
          />

          <CartesianGrid
            strokeDasharray="4 4"
            stroke={dividerColour}
            vertical={false}
          />

          <Line
            type="monotone"
            dataKey="yAxis"
            stroke={dividerColour}
            name={yAxis}
            strokeWidth={2}
            dot={{
              stroke: dividerColour,
              strokeWidth: 2,
              fill: backgroundColor,
              r: 3,
            }}
            isAnimationActive={false}
          />
        </LineChart>
      </ResponsiveContainer>
    </StyledChart>
  );
};

const mapStateToProps = (state: RootState) => ({
  theme: themeSelector(state),
});

export const SingleLineChart = connect(mapStateToProps)(Chart);

export { SingleLineChart as default };

How to enable recommended rules?

Hi!

Could you please explain how to enable and mix recommended rules, like:

  • eslint/recommended
  • typescript-eslint/recommended
  • airbnb

I tried the following:

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

This looks like working, is it the correct way?

Thanks!

Error: `sourceCode.isSpaceBetween is not a function Occurred while linting`

ESLint config:
{ "extends": ["airbnb-typescript"], "parserOptions": { "project": "./tsconfig.json", }, "rules": { "semi": "error" } }

package.json:
{ "name": "prettier-test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "@typescript-eslint/eslint-plugin": "^2.19.2", "@typescript-eslint/parser": "^2.19.2", "eslint": "^6.1.0", "eslint-config-airbnb": "^18.0.1", "eslint-config-airbnb-typescript": "^7.0.0", "eslint-plugin-import": "^2.20.1", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.18.3", "eslint-plugin-react-hooks": "^1.7.0", "typescript": "^3.7.5" } }

'React' is defined but never used @typescript-eslint/no-unused-vars

Hello everyone!
I have met the problem with .tsx files:
'React' is defined but never used @typescript-eslint/no-unused-vars.

I have the only record in .eslintrc.json:
{ "extends": ["airbnb-typescript"] }

Could you help, how to resolve this problem?

I can resolve this problem with setting for "@typescript-eslint/no-unused-vars" next value:
"varsIgnorePattern": "React"
but it is not very correct.

Thank you!

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
npm
package.json
  • eslint-config-airbnb-base ^15.0.0
  • @typescript-eslint/eslint-plugin 7.1.0
  • @typescript-eslint/parser 7.1.0
  • doctoc 2.2.1
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • husky 9.0.11
  • lint-staged 15.2.2
  • npm-run-all2 6.1.2
  • prettier 3.2.5
  • prettier-package-json 2.8.0
  • typescript 5.3.3
  • @typescript-eslint/eslint-plugin ^7.0.0
  • @typescript-eslint/parser ^7.0.0
  • eslint ^8.56.0

  • Check this box to trigger a request for Renovate to run again on this repository

[no-undef]: consider regression

Hey, I just upgraded to v11 and got a lot of 'no-undef' errors in my TypeScript files. I went to investigate what happened and realized that the lines that disabled the 'no-undef' rule were removed in #129.

I figured that it's because typescript-eslint's parser now allows users to specify "libs" available in the global scope, which may have lead to the conclusion this would fix the no-undef duplication error.

However, it doesn't allow users to specify external type packages. So if a user has any packages that declare global variables, you'll still get no-undef rules (e.g. .spec files).

I decided not to PR because I think this should be evaluated by the team before, but I can definetly help if you guys agree.

Rule "@typescript-eslint/indent" wrong expected indentation with decorators

When a class method has parameters with a decorator eslint expect 1 indent more except for the first parameter

.eslintrc.js

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    sourceType: 'module',
  },
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'airbnb-typescript/base',
  ],
};

index.ts

export default class MyClass {
  someValue = '';

  myMethod(
    @Query() param1: string,
    @Query() param2: string, // Expected indentation of 6 spaces but found 4
    @Query() param3: string, // Expected indentation of 6 spaces but found 4
  ): string {
    return `${this.someValue}${param1}${param2}${param3}`;
  }
}
eslint-config-airbnb-typescript-decorator-indent-error/src/index.ts
  8:1  error  Expected indentation of 6 spaces but found 4  @typescript-eslint/indent
  9:1  error  Expected indentation of 6 spaces but found 4  @typescript-eslint/indent

✖ 2 problems (2 errors, 0 warnings)
  2 errors and 0 warnings potentially fixable with the `--fix` option.

I made a minimal project to test this eslint-config-airbnb-typescript-decorator-indent-error

Configuration doesn't work

I installed https://github.com/typescript-eslint/typescript-eslint/ then performed steps from https://www.npmjs.com/package/eslint-config-airbnb-typescript (without React). I got the following errors:



C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components>npm install --save-dev eslint-config-airbnb-typescript eslint-plugin-import@^2.20.1 @typescript-eslint/eslint-plugin@^2.24.0
npm WARN [email protected] requires a peer of [email protected] - 6.x but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/[email protected] requires a peer of eslint@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/[email protected] requires a peer of eslint@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^5.16.0 || ^6.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^6.2.3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-react@^7.19.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-react-hooks@^2.5.0 || ^1.7.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^5.16.0 || ^6.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/[email protected] requires a peer of eslint@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @typescript-eslint/[email protected] requires a peer of eslint@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.

+ [email protected]
+ [email protected]
+ @typescript-eslint/[email protected]
added 68 packages from 40 contributors, removed 106 packages, updated 35 packages and audited 103 packages in 19.366s
found 0 vulnerabilities


C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components>yarn eslint . --ext .ts
yarn run v1.22.4
error Command "eslint" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components>eslint . --ext .ts     
'eslint' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components>npx eslint --ext .ts .    
npx: installed 136 in 8.026s

Oops! Something went wrong! :(

ESLint: 7.0.0

Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.js': Cannot find module 'eslint'
Require stack:
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\node_modules\@typescript-eslint\experimental-utils\dist\ts-eslint\Linter.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\node_modules\@typescript-eslint\experimental-utils\dist\ts-eslint\index.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\node_modules\@typescript-eslint\experimental-utils\dist\eslint-utils\RuleTester.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\node_modules\@typescript-eslint\experimental-utils\dist\eslint-utils\index.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\node_modules\@typescript-eslint\experimental-utils\dist\index.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\dist\analyze-scope.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\dist\parser.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\lib\cli-engine\config-array-factory.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\lib\cli-engine\cli-engine.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\lib\eslint\eslint.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\lib\eslint\index.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\lib\cli.js
- C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\bin\eslint.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\parser\node_modules\@typescript-eslint\experimental-utils\dist\ts-eslint\Linter.js:4:18)
    at Module._compile (C:\Users\Darek\AppData\Roaming\npm-cache\_npx\11560\node_modules\eslint\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)

C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components>

"comma-dangle" rule broken with enums

  1. Airbnb specifies in rule 20.2 of the style guide that we should use dangling commas.

  2. This is expressed in the ESLint config here:
    https://github.com/iamturns/eslint-config-airbnb-typescript/blob/master/lib/shared.js#L54-L57

    // require trailing commas in multiline object literals
    'comma-dangle': ['error', {
      arrays: 'always-multiline',
      objects: 'always-multiline',
      imports: 'always-multiline',
      exports: 'always-multiline',
      functions: 'always-multiline',
    }],

For reference, the documentation for the comma-dangle rule is documented here:
https://github.com/eslint/eslint/blob/master/docs/rules/comma-dangle.md#options

As we can see, the Airbnb config specifies "always-multiline" for all 5 object options.

  1. This repository extends the base config here:
    https://github.com/iamturns/eslint-config-airbnb-typescript/blob/master/lib/shared.js#L54-L57
    // Replace Airbnb 'comma-dangle' rule with '@typescript-eslint' version
    // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-dangle.md
    'comma-dangle': 'off',
    '@typescript-eslint/comma-dangle': baseStyleRules['comma-dangle'],

For reference, the documentation for the @typescript-eslint/comma-dangle rule is located here:
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-dangle.md

As we can see, the TypeScript version of the rule adds 3 new object options: enums, generics, and tuples.

However, this repository does not specify "always-multiline" for these 3 new object options. This is a bug, as it should almost certainly do so. For example, this bug results in the following code:

enum foo {
  thing1: string,
  thing2: string,
  thing3: string,
}

being automatically fixed (by eslint --fix) to this:

enum foo {
  thing1: string,
  thing2: string,
  thing3: string
}

To fix this bug, this repository could replace the above code snippet with the following code:

    // Replace Airbnb 'comma-dangle' rule with '@typescript-eslint' version
    // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-dangle.md
    'comma-dangle': 'off',
    '@typescript-eslint/comma-dangle': ['error', {
      arrays: 'always-multiline',
      objects: 'always-multiline',
      imports: 'always-multiline',
      exports: 'always-multiline',
      functions: 'always-multiline',
      enums: 'always-multiline',
      generics: 'always-multiline',
      tuples: 'always-multiline',
    }],

Or perhaps, less explicitly and using the spread operator:

    // Replace Airbnb 'comma-dangle' rule with '@typescript-eslint' version
    // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-dangle.md
    'comma-dangle': 'off',
    '@typescript-eslint/comma-dangle': [baseStyleRules['comma-dangle'][0], {
      ...baseStyleRules['comma-dangle'][1],
      enums: baseStyleRules['comma-dangle'][1].arrays,
      generics: baseStyleRules['comma-dangle'][1].arrays,
      tuples: baseStyleRules['comma-dangle'][1].arrays,
    }],

Thank you.

Getting typescript errors reported with js files

The readme says this works with both ts and js yet when I run npx eslint webpack.config.js I'm seeing lots of ts errors such as:

1:22  error    Require statement not part of import statement              @typescript-eslint/no-var-requires
   2:27  error    Require statement not part of import statement              @typescript-eslint/no-var-requires
   2:35  error    Unable to resolve path to module 'copy-webpack-plugin'      import/no-unresolved
   3:30  error    Require statement not part of import statement              @typescript-eslint/no-var-requires
   3:38  error    Unable to resolve path to module 'mini-css-extract-plugin'  import/no-unresolved
   4:14  error    Require statement not part of import statement              @typescript-eslint/no-var-requires
  30:24  warning  Missing return type on function                             @typescript-eslint/explicit-function-return-type

I'm using the base configuration.

.eslintrc:

{
  "root": true,
  "extends": [
    "airbnb-typescript/base",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"]
}

Using latest versions except [email protected].

Provided custom rules doesn't overwrite default settings

I provided these cutom rules to my .babelrc config file:

"rules": {
  "import/no-extraneous-dependencies": [
    "error",
    { "devDependencies": ["**/*.story.tsx"] }
  ]
}

and they doesn't overwrite default settings.

My whole config file looks like this:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "extends": [
    "airbnb-typescript",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended",
    "prettier/@typescript-eslint",
    "prettier/react"
  ],
  "env": {
    "node": true,
    "browser": true,
    "jest": true
  },
  "rules": {
    "import/no-extraneous-dependencies": [
      "error",
      { "devDependencies": ["**/*.story.tsx"] }
    ]
  }
}

Installed versions of packages:

"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.6.0",
"eslint": "5.16.0",
"eslint-config-airbnb-typescript": "1.1.0",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-react": "7.12.4",

Connect airbnb reports to sonar

Hi,

Previously I have been using tslint-config-airbnb and in my sonar-properties file had this config:

...
sonar.exclusions=**/node_modules/**
sonar.typescript.tsconfigPath=tsconfig.json
sonar.typescript.tslint.reportPaths=tslint-report.json

On my package.json I had this run script:

"sonar-tslint": "npm run tslint:json || npm run sonar"

Now tslint are deprecated and use this packages:

     eslint-config-airbnb": "^18.0.1",
    "eslint-config-airbnb-typescript": "^6.3.1",
    "eslint-config-prettier"

And my sonar file looks like this:

...
sonar.exclusions=**/node_modules/**
sonar.typescript.tsconfigPath=tsconfig.json

What would be a valid configuration to integrate eslint config airbnb typescript with sonar?

Thanks

New @typescript-eslint v4 rules: no-shadow, no-redeclare

@typescript-eslint v4 adds these new rules:

This is required since the base rules report false positives in TypeScript (e.g. no-shadow reports enums) with the v4 typescript-eslint release (due to breaking changes in the scope analysis engine).

  • The no-shadow rule should be turned off and replaced with @typescript-eslint/no-shadow
  • The no-redeclare rule should be turned off and replaced with @typescript-eslint/no-redeclare

naming-convention error for React Functional Components

Hi!
I just upgraded to v8.0.0 and I have problems with @typescript-eslint/naming-convention and React Functional Components.

Say I have something like this:

const MyComponent = (props: Props) => {...}

However that results in:

Variable name MyComponent must match one of the following formats: camelCase, UPPER_CASE        @typescript-eslint/naming-convention

Is this a bug or a feature? :)

7.0.0 tsconfig errors (The file must be included) & (File not found)

When I migrate to v7.0.0 with linting in package.json scripts such as:
tsc --project ./src/tsconfig.dev.json --noEmit && eslint **/*.{ts,json,js} *.* .*.js
& eslintrc config with

parserOptions: {
	project: './src/tsconfig.dev.json',
	extraFileExtensions: ['.json'],
},

have a list of errors (package.json & even *.spec files!):

C:\Projects\systemjs-ts-es6-vue\src\tsconfig.dev.json
  0:0  error  Parsing error: File 'c:\projects\systemjs-ts-es6-vue\src\tsconfig.dev.json' not found

C:\Projects\systemjs-ts-es6-vue\package-lock.json
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: package-lock.json.
The file must be included in at least one of the projects provided

C:\Projects\systemjs-ts-es6-vue\package.json
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: package.json.
The file must be included in at least one of the projects provided

Test project before migrating

Conflicting semicolon rules

Screen Shot 2019-05-12 at 9 02 50 AM

Eslint Configuration

module.exports = {
    "env": {
        "browser": true,
        "es6": true,
        "node": true
    },
    // "extends": "eslint:recommended",
    // "extends": "plugin:@typescript-eslint/recommended",
    "extends": [
        "airbnb-typescript/base"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    // "parserOptions": {
    //     "ecmaVersion": 2018,
    //     "sourceType": "module"
    // },
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
    }
};

Package.json

{
  "name": "preql",
  "version": "0.1.0",
  "description": "A program for transpiling PreQL to chosen SQL dialects",
  "main": "./dist/index.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "serverless-demo": "serverless invoke -f transpile-mysql -p ./test/data/1.yaml | fx this.value"
  },
  "keywords": [
    "sql",
    "ddl"
  ],
  "author": "Jonathan M. Wilbur <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "ajv": "^6.10.0",
    "js-yaml": "^3.13.1"
  },
  "devDependencies": {
    "@types/ajv": "^1.0.0",
    "@types/aws-lambda": "^8.10.24",
    "@types/js-yaml": "^3.12.1",
    "@typescript-eslint/eslint-plugin": "^1.8.0",
    "@typescript-eslint/parser": "^1.8.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb-typescript": "^4.0.0",
    "eslint-plugin-import": "^2.17.2",
    "serverless-plugin-typescript": "github:EugeneDraitsev/serverless-plugin-typescript#build",
    "typescript": "^3.4.3"
  }
}

Sample offending file

This issue happens with other similar files, too.

export default
interface Logger {
  debug (path: string[], event: string): void;
  info (path: string[], event: string): void;
  warn (path: string[], event: string): void;
  error (path: string[], event: string): void;
};

Remove unnecessary files from the npm package

There are few files that could be deleted from npm, it will reduce the package size and time of loading the package
Screenshot from 2020-11-03 02-14-48

for example:
.vscode
.editorconfig
...
and other files that are used for developing the package

I guess it will be easy to add file .npmignore into the project that contains smth like this

*
!lib/**/*
!dist/**/*
!package.json
!README.md
!LICENCE
... 

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

File: renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error near // Do

BUG [`@typescript-eslint/no-unused-expressions`]: Rule config is invalid

ESLint config

Info

  • OS: macOS 10.15.7
  • Node: v15.8.0

Dependencies

package.json (partially shown)

{
    "eslint": "^7.20.0",
    "@typescript-eslint/eslint-plugin": "^4.14.2",
    "eslint-config-airbnb-typescript": "^12.3.1",
    "eslint-config-airlight-react": "^1.1.3",
}

Repro

.eslintrc

{
  "extends": "airlight-react"
}

Log

❯ yarn eslint .
yarn run v1.22.10
$ /Users/dalisoft/Desktop/Workdir/ADV/MyScreen/myscreen-frontend-new/node_modules/.bin/eslint .

Oops! Something went wrong! :(

ESLint: 7.20.0

Error: .eslintrc » eslint-config-airlight-react » eslint-config-airbnb-typescript » /Users/dalisoft/Desktop/Workdir/ADV/MyScreen/myscreen-frontend-new/node_modules/eslint-config-airbnb-typescript/lib/shared.js:
        Configuration for rule "@typescript-eslint/no-unused-expressions" is invalid:
        Value {"allowShortCircuit":false,"allowTernary":false,"allowTaggedTemplates":false,"enforceForJSX":false} should NOT have additional properties.

Invalid configuration for rule "@typescript-eslint/indent"

Getting an error with this plugin which breaks my vim eslint plugin integration:

[Error  - 1:08:39 PM] .eslintrc.yml » eslint-config-airbnb-typescript » 
/home/dori/Projects/Work/project-v3/client/node_modules/eslint-config-airbnb-typescript/lib/shared.js: 	
Configuration for rule "@typescript-eslint/indent" is invalid: 	
Value {"SwitchCase":1,"VariableDeclarator":1,"outerIIFEBody":1,"FunctionDeclaration":{"parameters":1,"body":1},"FunctionExpression":{"parameters":1,"body":1},"CallExpression":{"arguments":1},"ArrayExpression":1,"ObjectExpression":1,"ImportDeclaration":1,"flatTernaryExpressions":false,"ignoredNodes":["JSXElement","JSXElement > *","JSXAttribute","JSXIdentifier","JSXNamespacedName","JSXMemberExpression","JSXSpreadAttribute","JSXExpressionContainer","JSXOpeningElement","JSXClosingElement","JSXFragment","JSXOpeningFragment","JSXClosingFragment","JSXText","JSXEmptyExpression","JSXSpreadChild"],"ignoreComments":false,"offsetTernaryExpressions":false} 
should NOT have additional properties. 

Using eslint-config-airbnb-typescript 7.2.1

No Definition found for "comma_dangle", "no-loop-func", "no-redeclare" and "no-shadow"

So I recently encountered some issue with a boilerplate repo of mine when I moved to higher versions of several tools. It is probably my mistake but since I could not for the love of the code gods find the issue.

ESLint is complaining about 4 missing rules:

Definition for rule '@typescript-eslint/comma-dangle' was not found.
Definition for rule '@typescript-eslint/no-loop-func' was not found.
Definition for rule '@typescript-eslint/no-redeclare' was not found.
Definition for rule '@typescript-eslint/no-shadow' was not found.

The following dependencies are in my package.json:

"devDependencies": {
    "@types/chai": "4.2.11",
    "@types/mocha": "7.0.2",
    "@types/node": "14.0.13",
    "@typescript-eslint/eslint-plugin": "^4.4.1",
    "@typescript-eslint/parser": "4.13.0",
    "chai": "4.2.0",
    "eslint": "^7.15.0",
    "eslint-config-airbnb-typescript": "^12.0.0",
    "eslint-config-prettier": "7.1.0",
    "eslint-plugin-chai-expect": "2.2.0",
    "eslint-plugin-eslint-comments": "3.2.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-mocha": "8.0.0",
    "eslint-plugin-prettier": "3.3.1",
    "eslint-plugin-react": "^7.20.3",
    "eslint-plugin-react-hooks": "^4.0.8",
    "grunt": "1.3.0",
    "grunt-cli": "1.3.2",
    "grunt-contrib-clean": "2.0.0",
    "grunt-contrib-watch": "1.1.0",
    "grunt-eslint": "23.0.0",
    "grunt-git": "1.0.14",
    "grunt-shell": "3.0.1",
    "grunt-string-replace": "1.3.1",
    "grunt-ts": "6.0.0-beta.22",
    "mocha": "8.2.1",
    "nyc": "15.1.0",
    "prettier": "2.2.1",
    "ts-mocha": "8.0.0",
    "ts-node": "9.1.1",
    "tsconfig-paths": "3.9.0",
    "typedoc": "0.17.7",
    "typescript": "4.1.3"
},

And my .eslintrc.js file looks as follows:

module.exports = {
  plugins: ['@typescript-eslint', 'eslint-comments', 'mocha', 'chai-expect'],
  extends: [
    'airbnb-typescript',
    'airbnb/hooks',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'plugin:eslint-comments/recommended',
    'plugin:mocha/recommended',
    'plugin:chai-expect/recommended',
  ],
  env: {
    es2020: true,
    mocha: true,
    node: true,
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: './tsconfig.json',
    ecmaVersion: 11,
    sourceType: 'module',
  },
  settings: {
    'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      node: {
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
      },
    },
  },
  rules: {
    'no-unused-vars': 'off',
    '@typescript-eslint/no-unused-vars': 'error',
    'no-useless-constructor': 'off',
    '@typescript-eslint/no-useless-constructor': 'error',
    'linebreak-style': ['error', 'windows'],
    'import/prefer-default-export': 'off',
    'importDeclaration': 'off',
    'no-console': 'off',
    'prefer-arrow-callback': 'off',
  },
};

Error: Failed to load config "prettier" to extend from.

[Error - 下午12:51:12] ESLint stack trace:
[Error - 下午12:51:12] Error: Failed to load config "prettier" to extend from.
Referenced from: D:\rs-test\minigrep\node_modules\eslint-config-airbnb-typescript\.eslintrc.js
    at configInvalidError (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\config-array-factory.js:295:9)
    at ConfigArrayFactory._loadExtendedShareableConfig (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\config-array-factory.js:876:23)
    at ConfigArrayFactory._loadExtends (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\config-array-factory.js:776:25)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\config-array-factory.js:715:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\config-array-factory.js:660:20)
    at _normalizeObjectConfigData.next (<anonymous>)
    at ConfigArrayFactory.loadInDirectory (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\config-array-factory.js:508:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:367:46)
    at CascadingConfigArrayFactory.getConfigArrayForFile (D:\rs-test\minigrep\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:288:18)

version:
"eslint-config-airbnb-typescript": "10.0.0",

Should you add it to dependencies instead of devDependencies?

Update to ESLint 6

Update dependencies, because eslint-config-airbnb has been updated for ESLint 6 support 😄

Feature request: expand airbnb's list of files for `import/no-extraneous-dependencies` to include TS files

When importing packages into config files written in TS (eg, webpack.config.ts), an error will be reported claiming webpack should be a dependency, not a dev dependency

Screenshot 2020-08-03 at 16 50 01

In the spirit of airbnb's config for import/no-extraneous-dependencies, it would be great for eslint-config-airbnb-typescript to extend that list to also include TS files.

version of:
"eslint-config-airbnb-typescript": "^8.0.2",

Error in .eslintrc

I got this error in my .eslintrc:

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: .eslintrc.js.
The file must be included in at least one of the projects provided.

After adding this package. Here is a copy of my .eslintrc:

module.exports = {
    parser: "@typescript-eslint/parser",
    env: {
      browser: true,
      es2020: true
    },
    extends: [
      'airbnb-typescript',
      'plugin:react/recommended',
      'plugin:@typescript-eslint/recommended',
      'prettier/@typescript-eslint',
      'plugin:import/typescript',
      'prettier',
      'prettier/react',
      'plugin:prettier/recommended'
    ],
    parserOptions: {
      project: './tsconfig.json',
    },
    plugins: ['react', '@typescript-eslint'],
    rules: {
      'no-console': 2,
      'comma-dangle': ['error', 'never'],
      'import/no-unresolved': [2, { commonjs: true }],
      'import/extensions': [
        'error',
        'ignorePackages',
        { ts: 'never', tsx: 'never' }
      ],
      "@typescript-eslint/explicit-module-boundary-types": "off"
    }
  };

Please help me. Thanks.

Definition for rule was not found

Hello !

I'm trying to use eslint-config-airbnb-typescript in my project but WebStorm throw this errors:

ESLint: Definition for rule '@typescript-eslint/comma-dangle' was not found.(@typescript-eslint/comma-dangle)
ESLint: Definition for rule '@typescript-eslint/no-loop-func' was not found.(@typescript-eslint/no-loop-func)
ESLint: Definition for rule '@typescript-eslint/no-redeclare' was not found.(@typescript-eslint/no-redeclare)
ESLint: Definition for rule '@typescript-eslint/no-shadow' was not found.(@typescript-eslint/no-shadow)

.eslintrc.js:

module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'airbnb-typescript/base',
  ],
  parserOptions: {
    project: './tsconfig.eslint.json',
  },
};

tsconfig.eslint.json:

{
  "extends": "./tsconfig.json",
  "include": ["./src", ".eslintrc.js"]
}

Dev dependencies from package.json:

{
    "@types/node": "^14.0.13",
    "@typescript-eslint/eslint-plugin": "^2.29.0",
    "@typescript-eslint/eslint-plugin-tslint": "^4.9.0",
    "@typescript-eslint/parser": "^2.34.0",
    "concurrently": "^5.3.0",
    "eslint": "^7.15.0",
    "eslint-config-airbnb-typescript": "^12.0.0",
    "eslint-plugin-import": "^2.22.1",
    "nodemon": "^2.0.6",
    "typescript": "^4.1.2"
  }

All this rules seems to be present from the lib/shared.js file.

Did I missed something ?

Error since bumping to 7.0.0

Hi,

First of all thanks for the package!

We are using this and have just bumped to 2.19.0 and ahve the following error when eslinting:

$ NODE_ENV=development eslint src --ext .js,.jsx,.ts,.tsx
TypeError: sourceCode.isSpaceBetween is not a function
Occurred while linting /Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/src/apollo/apollo.ts:1
    at validateCommaSpacing (/Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/comma-spacing.js:88:44)
    at /Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/comma-spacing.js:132:21
    at Array.forEach (<anonymous>)
    at Program:exit (/Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/comma-spacing.js:126:35)
    at /Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/eslint/lib/util/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (/Users/alexander.janet/workspace/github.com/Shuttlerock/spielberg-ui/node_modules/eslint/lib/util/node-event-generator.js:303:14)
error Command failed with exit code 2.

I followed the breaking change migration.

Any idea if this is on your side?

Typescript version 4.1.3 not supported

Hey all! Thanks for the great lint configuration for typescript! I'm running TS 4.1.3 which is currently throwing the below unsupported version error due to this package using an out of date version of @typescript-eslint/parser which can be seen here:

├─┬ @typescript-eslint/[email protected]
│ └─┬ @typescript-eslint/[email protected]
│   └── @typescript-eslint/[email protected]  deduped
├─┬ @typescript-eslint/[email protected]
│ └── @typescript-eslint/[email protected]
└─┬ [email protected]
  └─┬ @typescript-eslint/[email protected]
    └── @typescript-eslint/[email protected]

Here's the exact error:

=============

WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.3.1 <4.1.0

YOUR TYPESCRIPT VERSION: 4.1.3

Please only submit bug reports when using the officially supported version.

=============

I'm hoping that some of the outstanding renovate PRs can be merged, such as #175 which will hopefully allow us to use this module with TS 4.1! Thanks for your time!

Missing `@typescript-eslint/parser` in README

You have the:

@typescript-eslint/eslint-plugin@^3.1.0 \

in the examples, but missed the:

"@typescript-eslint/parser": "^3.1.0"

To get the basic setup going with no React and Prettier I need:

pnpm install --save-dev \
    @typescript-eslint/eslint-plugin@^3.1.0 \
    @typescript-eslint/parser@^3.1.0 \
    eslint@^7.1.0 \
    eslint-config-airbnb-typescript@^8.0.1 \
    eslint-config-prettier@^6.11.0 \
    eslint-plugin-import@^2.20.1 \
    typescript@^3.9.
module.exports = {
  root: true,
  parser: "@typescript-eslint/parser",
  parserOptions: {
    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
    tsconfigRootDir: __dirname,
    project: ["./tsconfig.json"],
  },
  plugins: ["@typescript-eslint"],
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "airbnb-typescript/base",
    "prettier",
    "prettier/@typescript-eslint",
  ],
  rules: { },
}

Thanks for an awesome application!

Airbnb-typescript creates syntax error when linting react HOC with generics in --fix mode

I've encountered a really interesting issue using airbnb-typescript config with --fix flag.

For some reason, airbnb-typescript eslint config doesn't like react higher order components with generics and tries to wrap generic opening tag character with parenthesis.

So, following code:

const HOCFails = <P extends object>(
  Component: React.ComponentType<P>,
): React.ComponentType<P> => {
  const withFClass = (props: P) => <Component {...props as P} />;
  return withFClass;
};

becomes:

const HOCFails = (<)P extends object>(
  Component: React.ComponentType<P>,
): React.ComponentType<P> => {
  const withFClass = (props: P) => <Component {...props as P} />;
  return withFClass;
};

and eslint exists with:
error Parsing error: Expression expected

However, it works on custom eslint + prettier + eslint-typescript setup.

I created a repo to reproduce the issue with both failing and passing configs:
https://github.com/sergesemashko/airbnb-typescript-eslint-test

I'm really out of guesses at this point and looking for any troubleshooting tips as I would like to keep using airbnb-typescript

Got `npm install` Warnings When Use `eslint-config-airbnb-base`

I got warnings when use eslint-config-airbnb-base (no React support).

npm WARN [email protected] requires a peer of mock-socket@~8.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^6.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-react@^7.11.0 but none is installed. You must install peer dependencies yourself.

no-dupe-class-members error

Hey 👋

As you know it's possible to overload functions and methods in TypeScript.

I receive no-dupe-class-members error when I try to overload class method:

class Foo {
  bar(arg0: string): void;
  bar(arg0: string, arg1: string): void;
  bar(arg0: string, arg1?: string) {
    // implementation
  }
}

Also TypeScript throws an error if we have duplicate identifiers in our code:

// Duplicate identifier 'bar'.
class Foo {
  bar = 1;
  bar = 1;
}

// Duplicate identifier 'bar'.
class Foo {
  get bar() {
    return 1;
  }
  get bar() {
    return 1;
  }
}

Maybe this rule can be disabled? Or there might be some unexpected consequences 🤔

Here are some links that might be useful:

Configuration for rule "import/no-cycle" is invalid

Using the new Eslint 7.3.0 version, this error is reported:

.eslintrc.js »
 eslint-config-airbnb-typescript/base »
node_modules/eslint-config-airbnb-base/index.js » 
/opt/desenvolvimento/haizen/bridi-back/node_modules/eslint-config-airbnb-base/rules/imports.js: 
Configuration for rule "import/no-cycle" is invalid: 
Value null should be integer. 

Shared eslint-config in monorepo

I updated to 7.0.0. We have a monorepo structure as follows:

eslint-config
eslint-config/.eslintrc.js
package-a
package-a/tsconfig-a.json
package-b
package-b/tsconfig-b.json

The packages package-a and package-a both consume .eslintrc.js from the shared eslint-config package. But both packages use different TypeScript configuration files.

I struggle with configuring the parserOptions.project option (see #63) in a way, that each package uses it's dedicated tsconfig file. Any ideas?

@typescript-eslint/no-unused-vars throws error although used as a type

import { Controller, Get } from '@nestjs/common';
import {
  HealthCheckService,
  HealthCheck,
  MongooseHealthIndicator,
} from '@nestjs/terminus';

@Controller('health')
export class HealthController {
  constructor(
    private health: HealthCheckService,
    private db: MongooseHealthIndicator,
  ) {}

  @Get()
  @HealthCheck()
  check() {
    return this.health.check([() => this.db.pingCheck('mongodb')]);
  }
}

I get the following error

  3:3  error  'HealthCheckService' is defined but never used       @typescript-eslint/no-unused-vars
  5:3  error  'MongooseHealthIndicator' is defined but never used  @typescript-eslint/no-unused-vars

Although I am using HealthCheckService and MongooseHealthIndicator as a type

This is what my eslintrc.js file looks like

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin'],
  extends: [
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'prettier',
    'prettier/@typescript-eslint',
    'airbnb-typescript',
    'eslint:recommended',
  ],
  root: true,
  env: {
    node: true,
    jest: true,
  },
  rules: {
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',    
  },
};

Prop types error in functional component

I have a file that contains a component

const Component: React.FC<ComponentProps> = ({
  reallyLongProp,
  alsoReallyLong
}) => {
  const [count, setCount] = useState(0);
  return (
    <ul>
      <li>{reallyLongProp}</li>
      <li>{alsoReallyLong}</li>
      <li>{count}</li>
      <li>
        <button type="button" onClick={(): void => setCount(count + 1)}>
          Increment
        </button>
      </li>
    </ul>
  );
};

And I'm getting these errors:

  • react/prop-types: 'reallyLongProp' is missing in props validation
  • react/prop-types: 'alsoReallyLong' is missing in props validation

react/jsx-no-bind is invalid with latest version of ts, eslint, prettier

eslint-config-airbnb-typescript » /home/myuser/node_modules/eslint-config-airbnb/index.js » /home/myuser/node_modules/eslint-config-airbnb/rules/react.js:
Configuration for rule "react/jsx-no-bind" is invalid: Value {"ignoreRefs":true,"allowArrowFunctions":true,"allowFunctions":false,"allowBind":false,"ignoreDOMComponents":true} should NOT have additional properties.

"Error while loading rule '@typescript-eslint/no-implied-eval'" while migrating from 6.3.1 to 7.0.0

While working on a react-typescript application, I tried to setup eslint the same way I used to one month ago.

I ran the following command :

npm install eslint-config-airbnb-typescript \
            eslint-plugin-import \
            eslint-plugin-jsx-a11y \
            eslint-plugin-react \
            eslint-plugin-react-hooks \
            @typescript-eslint/eslint-plugin \
            --save-dev

With this eslint configuration :

parserOptions:
  ecmaVersion: 6

env:
  browser: true

extends:
  - airbnb-typescript
  - airbnb/hooks
  - plugin:@typescript-eslint/recommended

rules:
  react/react-in-jsx-scope: off

I ran npm run lint and I got an error :

What I expected

Eslint working as usual.

What I got

Error: Error while loading rule '@typescript-eslint/no-implied-eval': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /Users/skaas/project/src/App.test.tsx
    at Object.getParserServices (/Users/skaas/project/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/experimental-utils/dist/eslint-utils/getParserServices.js:15:15)
    at create (/Users/skaas/project/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-implied-eval.js:38:37)
    at Object.create (/Users/skaas/project/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/experimental-utils/dist/eslint-utils/RuleCreator.js:12:24)
    at createRuleListeners (/Users/skaas/project/node_modules/eslint/lib/linter/linter.js:746:21)
    at /Users/skaas/project/node_modules/eslint/lib/linter/linter.js:916:31
    at Array.forEach (<anonymous>)
    at runRules (/Users/skaas/project/node_modules/eslint/lib/linter/linter.js:861:34)
    at Linter._verifyWithoutProcessors (/Users/skaas/project/node_modules/eslint/lib/linter/linter.js:1157:31)
    at Linter._verifyWithConfigArray (/Users/skaas/project/node_modules/eslint/lib/linter/linter.js:1255:21)
    at Linter.verify (/Users/skaas/project/node_modules/eslint/lib/linter/linter.js:1210:25)

How did I fix it

I switched back to "eslint-config-airbnb-typescript": "^6.3.1" and it fixed the error.

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.