Skip to content

Instantly share code, notes, and snippets.

@KarmaBlackshaw
Last active January 30, 2023 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarmaBlackshaw/7247217d658eba3e7239fce64b75e2df to your computer and use it in GitHub Desktop.
Save KarmaBlackshaw/7247217d658eba3e7239fce64b75e2df to your computer and use it in GitHub Desktop.
ESLint Configurations

Eslint Configuration for API

Config

module.exports = {
  env: {
    browser: true,
    commonjs: true,
    es6: true,
    node: true
  },
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  parserOptions: {
    ecmaVersion: 2020
  },
  extends: [
    'standard',
    'eslint:recommended'
  ],
  rules: {
    'no-await-in-loop': 'off',
    'no-console': 'off',
    'no-useless-catch': 'off',
    eqeqeq: 'off',
    'prefer-regex-literals': 'off',
    'default-case': 'off',
    'comma-dangle': [
      'error',
      'never'
    ],
    'prefer-const': 'error',
    'arrow-parens': [
      2,
      'as-needed'
    ],
    'no-param-reassign': 'error',
    'object-curly-spacing': [
      'error',
      'always'
    ],
    curly: [
      2,
      'all'
    ],
    semi: [
      'error',
      'never'
    ],
    indent: [
      'error',
      2,
      {
        SwitchCase: 1,
        outerIIFEBody: 'off'
      }
    ],
    'comma-spacing': [
      'error',
      {
        before: false,
        after: true
      }
    ],
    'brace-style': [
      'error',
      '1tbs',
      {
        allowSingleLine: false
      }
    ],
    'no-unused-vars': [
      'error',
      {
        argsIgnorePattern: 'next|_.+',
        varsIgnorePattern: '_'
      }
    ],
    'quote-props': [
      'error',
      'as-needed'
    ],
    'no-multiple-empty-lines': [
      'error',
      {
        max: 1,
        maxEOF: 0
      }
    ]
  }
}

Dependencies

function install (dependencies) {
  const packages = Object.entries(dependencies)
      .map(([package, version]) => `${package}@${version}`)
      .join(' ')

  return `npm i --save-dev ${packages}`
}

install({
  "eslint": "7.32.0",
  "eslint-config-standard": "16.0.3",
  "eslint-plugin-import": "2.25.3",
  "eslint-plugin-node": "11.1.0",
  "eslint-plugin-promise": "4.3.1",
  "eslint-plugin-standard": "4.0.1"
})
/**
1. Copy and paste the function to the browser console
2. Copy the dependencies
3. Run the following: `install(**PASTE_THE_DEV_DEPENDENCIES_HERE**)`
*/
function install (dependencies) {
const packages = Object.entries(dependencies)
.map(([package, version]) => `${package}@${version}`)
.join(' ')
return `npm i --save-dev ${packages}`
}
module.exports = {
  root: true,

  env: {
    node: true,
    browser: true
  },

  globals: {
    define: true
  },

  extends: [
    'eslint:recommended',
    'plugin:vue/essential',
    'plugin:vue/recommended'
  ],

  parser: 'vue-eslint-parser',

  parserOptions: {
    parser: 'babel-eslint'
  },

  rules: {
    'array-bracket-spacing': [
      'error',
      'never'
    ],
    'array-callback-return': 'error',
    'arrow-parens': [
      'error',
      'as-needed'
    ],
    'object-curly-spacing': ['error', 'always'],
    'arrow-spacing': 'error',
    'block-spacing': 'error',
    'brace-style': 'error',
    'camelcase': 'off',
    'comma-dangle': 'error',
    'default-case': 'error',
    'eqeqeq': 'off',
    'indent': [
      'error',
      2,
      {
        'ignoredNodes': [
          'TemplateLiteral'
        ],
        'SwitchCase': 1
      }
    ],
    'no-alert': 'off',
    'no-await-in-loop': 'off',
    'no-console': 'off',
    'no-debugger': 'off',
    'no-else-return': 'error',
    'no-empty-function': 'error',
    'no-labels': 'off',
    'no-loop-func': 'error',
    'no-multiple-empty-lines': [
      'error',
      {
        'max': 1
      }
    ],
    'no-new': 'off',
    'no-prototype-builtins': 'off',
    'no-return-await': 'error',
    'no-shadow': 'error',
    'no-useless-catch': 'off',
    'no-var': 'error',
    'prefer-const': 'error',
    'prefer-rest-params': 'error',
    'prefer-spread': 'error',
    semi: ['error', 'never'],
    'quotes': [
      'error',
      'single',
      {
        'avoidEscape': true
      }
    ],
    'require-await': 'error',
    'template-curly-spacing': 'off',
    'vue/comma-spacing': [
      'error',
      {
        'before': false,
        'after': true
      }
    ],
    'vue/component-definition-name-casing': [
      'error',
      'PascalCase'
    ],
    'vue/component-name-in-template-casing': [
      'error',
      'kebab-case'
    ],
    'vue/custom-event-name-casing': [
      'error',
      'kebab-case',
      {
        'ignores': [
          '/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'
        ]
      }
    ],
    'vue/html-closing-bracket-newline': [
      'error',
      {
        'singleline': 'never',
        'multiline': 'always'
      }
    ],
    'vue/html-end-tags': 'error',
    'vue/html-indent': [
      'error',
      2,
      {
        'attribute': 1,
        'baseIndent': 1,
        'closeBracket': 0,
        'alignAttributesVertically': true,
        'ignores': []
      }
    ],
    'vue/html-self-closing': [
      'error',
      {
        'html': {
          'void': 'never',
          'normal': 'never',
          'component': 'always'
        },
        'svg': 'always',
        'math': 'always'
      }
    ],
    'vue/match-component-file-name': [
      'error',
      {
        'extensions': [
          'vue'
        ],
        'shouldMatchCase': false
      }
    ],
    'vue/max-attributes-per-line': [
      'error',
      {
        'singleline': 1
      }
    ],
    'vue/no-unused-properties': [
      'error',
      {
        'groups': [
          'props',
          'data',
          'computed',
          'methods'
        ]
      }
    ],
    'vue/no-v-html': 'off',
    'vue/require-default-prop': 'off',
    'vue/this-in-template': [
      'error',
      'never'
    ],
    'vue/v-bind-style': [
      'error',
      'shorthand'
    ],
    'vue/v-on-style': [
      'error',
      'shorthand'
    ]
  }
}
function install (dependencies) {
  const packages = Object.entries(dependencies)
      .map(([package, version]) => `${package}@${version}`)
      .join(' ')

  return `npm i --save-dev ${packages}`
}

install({
    "eslint": "^7.32.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^7.0.0"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment