Skip to content
代码片段 群组 项目
.eslintrc.yml 10.8 KB
更新 更旧
Lukas Eipert's avatar
Lukas Eipert 已提交
extends:
  - plugin:@gitlab/default
  - plugin:@gitlab/i18n
  - plugin:no-jquery/slim
  - plugin:no-jquery/deprecated-3.4
  - plugin:no-unsanitized/DOM
  - ./tooling/eslint-config/conditionally_ignore.js
Lukas Eipert's avatar
Lukas Eipert 已提交
globals:
  __webpack_public_path__: true
  gl: false
  gon: false
  localStorage: false
Lukas Eipert's avatar
Lukas Eipert 已提交
plugins:
Lukas Eipert's avatar
Lukas Eipert 已提交
settings:
  import/resolver:
    webpack:
      config: './config/webpack.config.js'
Lukas Eipert's avatar
Lukas Eipert 已提交
rules:
  import/no-commonjs: error
  import/no-default-export: off
Lukas Eipert's avatar
Lukas Eipert 已提交
  no-underscore-dangle:
    - error
    - allow:
  import/no-unresolved:
    - error
        # In FOSS, these import paths are rewritten using
        # NormalModuleReplacementPlugin, which import/no-unresolved doesn't
        # consider. See
        # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89831.
        - '^(ee|jh)_component/'
Mike Greiling's avatar
Mike Greiling 已提交
  lines-between-class-members: off
  # all offenses of no-jquery/no-animate-toggle are false positives ( $toast.show() )
  no-jquery/no-animate-toggle: off
  no-jquery/no-event-shorthand: off
  no-jquery/no-serialize: error
  promise/always-return: off
  promise/no-callback-in-promise: off
  '@gitlab/no-global-event-off': error
  '@gitlab/vue-no-new-non-primitive-in-template':
    - error
    - allowNames:
        - 'class(es)?$'
        - '^style$'
        - '^to$'
        - '^$'
        - '^variables$'
        - 'attrs?$'
  no-param-reassign:
    - error
    - props: true
      ignorePropertyModificationsFor:
        - acc
        - accumulator
        - el
        - element
        - state
      ignorePropertyModificationsForRegex:
        - '^draft'
    - error
    - groups:
        - builtin
        - external
        - internal
        - parent
        - sibling
        - index
      pathGroups:
        - pattern: ~/**
          group: internal
        - pattern: emojis/**
          group: internal
        - pattern: '{ee_,jh_,}empty_states/**'
          group: internal
        - pattern: '{ee_,jh_,}icons/**'
          group: internal
        - pattern: '{ee_,jh_,}images/**'
          group: internal
        - pattern: vendor/**
          group: internal
        - pattern: shared_queries/**
          group: internal
        - pattern: '{ee_,}spec/**'
          group: internal
        - pattern: '{ee_,jh_,}jest/**'
          group: internal
        - pattern: '{ee_,jh_,any_}else_ce/**'
          group: internal
        - pattern: ee/**
          group: internal
        - pattern: '{ee_,jh_,}component/**'
          group: internal
        - pattern: jh_else_ee/**
          group: internal
        - pattern: jh/**
          group: internal
        - pattern: '{test_,}helpers/**'
          group: internal
        - pattern: test_fixtures/**
          group: internal
      alphabetize:
        order: ignore
  'no-restricted-syntax':
    - error
    - selector: ImportSpecifier[imported.name='GlSkeletonLoading']
      message: 'Migrate to GlSkeletonLoader, or import GlDeprecatedSkeletonLoading.'
    - selector: ImportSpecifier[imported.name='GlSafeHtmlDirective']
      message: 'Use directive at ~/vue_shared/directives/safe_html.js instead.'
    - selector: Literal[value=/docs.gitlab.+\u002Fee/]
      message: 'No hard coded url, use `DOCS_URL_IN_EE_DIR` in `jh_else_ce/lib/utils/url_utility`'
    - selector: TemplateElement[value.cooked=/docs.gitlab.+\u002Fee/]
      message: 'No hard coded url, use `DOCS_URL_IN_EE_DIR` in `jh_else_ce/lib/utils/url_utility`'
    - selector: Literal[value=/(?=.*docs.gitlab.*)(?!.*\u002Fee\b.*)/]
      message: 'No hard coded url, use `DOCS_URL` in `jh_else_ce/lib/utils/url_utility`'
    - selector: TemplateElement[value.cooked=/(?=.*docs.gitlab.*)(?!.*\u002Fee\b.*)/]
      message: 'No hard coded url, use `DOCS_URL` in `jh_else_ce/lib/utils/url_utility`'
    - selector: Literal[value=/(?=.*about.gitlab.*)(?!.*\u002Fblog\b.*)/]
      message: 'No hard coded url, use `PROMO_URL` in `jh_else_ce/lib/utils/url_utility`'
    - selector: TemplateElement[value.cooked=/(?=.*about.gitlab.*)(?!.*\u002Fblog\b.*)/]
      message: 'No hard coded url, use `PROMO_URL` in `jh_else_ce/lib/utils/url_utility`'
    - selector: TemplateLiteral[expressions.0.name=DOCS_URL] > TemplateElement[value.cooked=/\u002Fjh|\u002Fee/]
      message: '`/ee` or `/jh` path found in docs url, use `DOCS_URL_IN_EE_DIR` in `jh_else_ce/lib/utils/url_utility`'
  no-restricted-properties:
    - error
    - object: window
      property: open
      message: 'Use `visitUrl` in `jh_else_ce/lib/utils/url_utility` to avoid cross-site leaks.'
  no-restricted-imports:
    - error
    - paths:
        - name: mousetrap
          message: 'Import { Mousetrap } from ~/lib/mousetrap instead.'
        - name: vuex
          message: 'See our documentation on "Migrating from VueX" for tips on how to avoid adding new VueX stores.'
        - name: '@sentry/browser'
          message: Use "import * as Sentry from '~/sentry/sentry_browser_wrapper';" instead
  unicorn/prefer-dom-node-dataset:
    - error
  no-unsanitized/method:
    - error
    - escape:
        methods: 'sanitize'
  no-unsanitized/property:
    - error
    - escape:
        methods: 'sanitize'
  # This rule will be enabled later.
  unicorn/no-array-callback-reference: off
  vue/no-undef-components:
    - error
    - ignorePatterns:
        - '^router-link$'
        - '^router-view$'
        - '^gl-emoji$'
  local-rules/require-valid-help-page-path: 'error'
  - files:
      - '{,ee/,jh/}spec/frontend*/**/*'
      '@gitlab/require-i18n-strings': off
      '@gitlab/no-runtime-template-compiler': off
      'import/no-dynamic-require': off
      'no-import-assign': off
      'no-restricted-syntax':
        - error
        - selector: CallExpression[callee.object.name=/(wrapper|vm)/][callee.property.name="setData"]
          message: 'Avoid using "setData" on VTU wrapper'
        - selector: MemberExpression[object.type!='ThisExpression'][property.type='Identifier'][property.name='$nextTick']
          message: 'Using $nextTick from a component instance is discouraged. Import nextTick directly from the Vue package.'
        - selector: Identifier[name='setImmediate']
          message: 'Prefer explicit waitForPromises (or equivalent), or jest.runAllTimers (or equivalent) to vague setImmediate calls.'
        - selector: ImportSpecifier[imported.name='GlSkeletonLoading']
          message: 'Migrate to GlSkeletonLoader, or import GlDeprecatedSkeletonLoading.'
        - selector: CallExpression[arguments.length=1][arguments.0.type='Literal'] CallExpression[callee.property.name='toBe'] CallExpression[callee.property.name='attributes'][arguments.length=1][arguments.0.value='disabled']
          message: Avoid asserting disabled attribute exact value, because Vue.js 2 and Vue.js 3 renders it differently. Use toBeDefined / toBeUndefined instead
        - selector: MemberExpression[object.object.name='Vue'][object.property.name='config'][property.name='errorHandler']
          message: 'Use setErrorHandler/resetVueErrorHandler from helpers/set_vue_error_handler.js instead.'
        - selector: Literal[value=/docs.gitlab.+\u002Fee/]
          message: 'No hard coded url, use `DOCS_URL_IN_EE_DIR` in `jh_else_ce/lib/utils/url_utility`'
        - selector: TemplateElement[value.cooked=/docs.gitlab.+\u002Fee/]
          message: 'No hard coded url, use `DOCS_URL_IN_EE_DIR` in `jh_else_ce/lib/utils/url_utility`'
        - selector: Literal[value=/(?=.*docs.gitlab.*)(?!.*\u002Fee\b.*)/]
          message: 'No hard coded url, use `DOCS_URL` in `jh_else_ce/lib/utils/url_utility`'
        - selector: TemplateElement[value.cooked=/(?=.*docs.gitlab.*)(?!.*\u002Fee\b.*)/]
          message: 'No hard coded url, use `DOCS_URL` in `jh_else_ce/lib/utils/url_utility`'
        - selector: Literal[value=/(?=.*about.gitlab.*)(?!.*\u002Fblog\b.*)/]
          message: 'No hard coded url, use `PROMO_URL` in `jh_else_ce/lib/utils/url_utility`'
        - selector: TemplateElement[value.cooked=/(?=.*about.gitlab.*)(?!.*\u002Fblog\b.*)/]
          message: 'No hard coded url, use `PROMO_URL` in `jh_else_ce/lib/utils/url_utility`'
        - selector: TemplateLiteral[expressions.0.name=DOCS_URL] > TemplateElement[value.cooked=/\u002Fjh|\u002Fee/]
          message: '`/ee` or `/jh` path found in docs url, use `DOCS_URL_IN_EE_DIR` in `jh_else_ce/lib/utils/url_utility`'
      no-restricted-properties: off
      no-unsanitized/method: off
      no-unsanitized/property: off
      local-rules/require-valid-help-page-path: off
  - files:
      - 'config/**/*'
      - 'scripts/**/*'
      - '*.config.js'
      - 'jest_resolver.js'
    rules:
      '@gitlab/require-i18n-strings': off
      import/no-extraneous-dependencies: off
      import/no-commonjs: off
      import/no-nodejs-modules: off
      filenames/match-regex: off
      no-console: off
Tom Quirk's avatar
Tom Quirk 已提交
  - files:
      - '*.stories.js'
    rules:
      filenames/match-regex: off
      '@gitlab/require-i18n-strings': off
  - files:
      - '*.graphql'
    plugins:
      - '@graphql-eslint'
    parserOptions:
      parser: '@graphql-eslint/eslint-plugin'
      operations: '{,ee/,jh/}app/**/*.graphql'
      schema: './tmp/tests/graphql/gitlab_schema_apollo.graphql'
    rules:
      filenames/match-regex: off
      spaced-comment: off
      # TODO: We need a way to include this rule + support ee_else_ce fragments
      #'@graphql-eslint/unique-fragment-name': error
      # TODO: Uncomment these rules when then `schema` is available
      #'@graphql-eslint/fragments-on-composite-type': error
Kyle Wiebers's avatar
Kyle Wiebers 已提交
      #'@graphql-eslint/known-argument-names': error
      #'@graphql-eslint/known-type-names': error
      '@graphql-eslint/no-anonymous-operations': error
      '@graphql-eslint/unique-operation-name': error
      '@graphql-eslint/require-id-when-available': error
      '@graphql-eslint/no-unused-variables': error
      '@graphql-eslint/no-unused-fragments': error
      '@graphql-eslint/no-duplicate-fields': error
Richard Chong's avatar
Richard Chong 已提交
  - files:
      - '{,ee/}spec/contracts/consumer/**/*'
Richard Chong's avatar
Richard Chong 已提交
    rules:
      '@gitlab/require-i18n-strings': off
  - files:
      - 'app/assets/javascripts/projects/settings/branch_rules/queries/branch_rules_details.query.graphql'
      - 'app/assets/javascripts/projects/settings/repository/branch_rules/graphql/mutations/create_branch_rule.mutation.graphql'
      - 'app/assets/javascripts/projects/settings/repository/branch_rules/graphql/queries/branch_rules.query.graphql'
      - 'ee/app/assets/javascripts/projects/settings/branch_rules/queries/branch_rules_details.query.graphql'
      - 'ee/app/assets/javascripts/projects/settings/repository/branch_rules/graphql/queries/branch_rules.query.graphql'
    rules:
      '@graphql-eslint/require-id-when-available': off
  - files:
      - '{,spec/}tooling/**/*'
    rules:
      'no-undef': off
      'import/no-commonjs': off
      'import/no-extraneous-dependencies': off
      'no-restricted-syntax': off
      '@gitlab/require-i18n-strings': off