---
parser: '@typescript-eslint/parser'
root: true
parserOptions:
  ecmaVersion: 2020
  sourceType: module
  ecmaFeatures:
    jsx: true
    impliedStrict: true
  project: ./tsconfig.json
plugins:
  - react
  - '@typescript-eslint/eslint-plugin'
  - react-hooks
  - jest
  - import
env:
  browser: true
  node: true
  shared-node-browser: true
  es6: true
  jest: true
globals:
  __DEV__: readonly
extends:
  - eslint:recommended
  - plugin:react/recommended
  - plugin:@typescript-eslint/recommended
  - plugin:import/errors
  - plugin:import/typescript
  - prettier
settings:
  react:
    version: detect
  import/resolver:
    typescript:
      alwaysTryTypes: true

rules:
  # built-in
  no-console: 2
  semi: 0
  no-await-in-loop: 2
  no-shadow: 0

  # react hooks
  react-hooks/rules-of-hooks: 2
  react-hooks/exhaustive-deps: 1

  # react
  react/prop-types: 0
  react/display-name: 1

  #typescript
  '@typescript-eslint/no-use-before-define': 0
  '@typescript-eslint/explicit-function-return-type':
    - 1
    - allowExpressions: true
  no-unused-vars: 0
  '@typescript-eslint/no-unused-vars':
    - 2
    - vars: all
      args: after-used
      ignoreRestSiblings: true
      argsIgnorePattern: ^_
  '@typescript-eslint/member-delimiter-style': 0
  '@typescript-eslint/no-shadow': 2
  '@typescript-eslint/no-extra-semi': 0
  '@typescript-eslint/no-duplicate-imports': 2

  #import
  import/order:
    - error
    - groups:
        - builtin
        - external
        - internal
        - - parent
          - sibling
      pathGroups:
        - pattern: '*.scss'
          group: index
          position: after
          patternOptions:
            matchBase: true
  import/no-useless-path-segments: 2

  import/no-cycle:
    - error

  no-restricted-imports:
    - warn
    - patterns:
        - lodash.*
        - microfrontends/*
        - '!microfrontends/ChildAppMounter'
        - _mocks/*
      paths:
        - lodash
        - name: yaml
          importNames:
            - stringify
          message: 'Please use yamlStringify from @utils instead of this'
        - name: react-router
          message: 'import from "react-router-dom" instead'
        - name: microfrontends
          message: Import from 'microfrontends' is only allowed in child apps
        - name: '@harnessio/uicore'
          importNames:
            - Color
            - FontVariation
            - Intent
            - Spacing
          message: import from "@harnessio/design-system" instead
  no-restricted-syntax:
    - error
    - selector: "CallExpression[callee.name='useContext'][arguments.0.name='PipelineContext']"
      message: 'Please use usePipelineContext instead'
    - selector: "CallExpression[callee.object.name='React'][callee.property.name='useContext'][arguments.0.name='PipelineContext']"
      message: 'Please use usePipelineContext instead'

overrides:
  - files:
      - '**/*.test.ts'
      - '**/*.test.tsx'
    rules:
      '@typescript-eslint/no-magic-numbers': 0
      '@typescript-eslint/no-non-null-assertion': 0
      '@typescript-eslint/no-non-null-asserted-optional-chain': 0
      '@typescript-eslint/no-explicit-any': 0
      no-await-in-loop: 0
      jest/consistent-test-it:
        - 2
        - fn: test
          withinDescribe: test
      jest/expect-expect: 2
      jest/no-disabled-tests: 2
      jest/no-commented-out-tests: 2
  - files:
      - services.tsx
    rules:
      '@typescript-eslint/explicit-function-return-type': 0
      '@typescript-eslint/no-explicit-any': 0
