module.exports = {
  root: true,
  parserOptions: {
    sourceType: 'script',
  },
  plugins: ['babel', 'filenames', '@lwc/eslint-plugin-lwc'],
  extends: [
    // https://github.com/vuejs/eslint-plugin-vue#bulb-rules
    'plugin:vue/recommended',
    // https://github.com/standard/standard/blob/master/docs/RULES-en.md
    'standard',
    // https://github.com/prettier/eslint-config-prettier
    'prettier',
    'prettier/standard',
    'prettier/vue',
  ],
  rules: {
    'standard/no-callback-literal': 0,
    'no-unused-vars': ['warn'],
    'vue/no-unused-vars': ['warn'],
    'no-restricted-globals': [
      'error',
      {
        name: 'localStorage',
        message:
          '\n已禁止直接使用 localStorage' +
          '\n请从 @/common/services/storage-service 导入 sdLocalStorage\n',
      },
      {
        name: 'sessionStorage',
        message:
          '\n已禁止直接使用 sessionStorage' +
          '\n请从 @/common/services/storage-service 导入 sdSessionStorage\n',
      },
    ],
    'no-restricted-imports': [
      'error',
      {
        paths: [
          {
            name: 'axios',
            message: '\n已禁止直接导入axios\n请从 @/common/services/axios-instance 导入\n',
          },
        ],
      },
    ],
    // 禁止style标签内写静态样式
    'vue/no-static-inline-styles': 'warn',
    // Only allow debugger in development
    'no-debugger': process.env.PRE_COMMIT ? 'error' : 'warn',
    // Only allow `console.log` in development
    'no-console': process.env.PRE_COMMIT ? ['error', { allow: ['warn', 'error'] }] : 'warn',
    // 组件名需要和文件名匹配
    'vue/match-component-file-name': [
      'warn',
      {
        extensions: ['js', 'jsx', 'vue'],
        shouldMatchCase: false,
      },
    ],
    // 组件名需要命名
    'vue/require-name-property': 'warn',
    // 不要使用保留的组件名
    'vue/no-reserved-component-names': [
      'error',
      // {
      //   disallowVueBuiltInComponents: true,
      //   disallowVue3BuiltInComponents: true,
      // },
    ],
    // 7.0 才支持，先注释掉
    // 'vue/no-potential-component-option-typo': [
    //   'warn',
    //   {
    //     presets: ['vue', 'vue-router'],
    //   },
    // ],
    'no-unused-expressions': 'off',
    'babel/no-unused-expressions': 'off',
    'import/no-relative-parent-imports': 'off',
    'import/order': 'off',
    'dot-notation': 'warn',
    'vue/array-bracket-spacing': 'error',
    'vue/arrow-spacing': 'error',
    'vue/block-spacing': 'error',
    'vue/brace-style': 'error',
    'vue/camelcase': 'error',
    // 'vue/comma-dangle': ['error', 'always-multiline'],
    'vue/component-name-in-template-casing': 'error',
    'vue/dot-location': ['error', 'property'],
    'vue/eqeqeq': 'error',
    'vue/key-spacing': 'error',
    'vue/keyword-spacing': 'error',
    'vue/no-boolean-default': ['error', 'default-false'],
    'vue/no-deprecated-scope-attribute': 'error',
    'vue/no-empty-pattern': 'error',
    'vue/object-curly-spacing': ['error', 'always'],
    'vue/padding-line-between-blocks': 'error',
    'vue/space-infix-ops': 'error',
    'vue/space-unary-ops': 'error',
    'vue/v-on-function-call': 'error',
    'vue/v-slot-style': [
      'error',
      {
        atComponent: 'v-slot',
        default: 'v-slot',
        named: 'longform',
      },
    ],
    'vue/valid-v-slot': 'error',
    'filenames/match-regex': [2, '^(?!oa-|xm-)[a-z0-9-]+$', false],
    'filenames/match-exported': [2, 'kebab', null, true],
    '@lwc/lwc/no-async-await': 'error',
    'vue/no-boolean-default': 'off',
  },
  overrides: [
    {
      files: ['src/**/*', 'src_product/**/*', 'src_custom/**/*', 'docs/**/*'],
      parserOptions: {
        parser: 'babel-eslint',
        sourceType: 'module',
      },
      env: {
        browser: true,
      },
    },
  ],
}
