Skip to content

Instantly share code, notes, and snippets.

@madhums
Last active October 3, 2024 11:56
Show Gist options
  • Save madhums/cdd89751cfa15ef1cb051910420ce665 to your computer and use it in GitHub Desktop.
Save madhums/cdd89751cfa15ef1cb051910420ce665 to your computer and use it in GitHub Desktop.
eslint prettier config
{
"presets": ["@babel/preset-env"],
"plugins": []
}
node_modules
styleguide
.next
.vscode
npm i eslint prettier eslint-config-prettier eslint-plugin-prettier @babel/core @babel/eslint-parser @babel/preset-env globals @eslint/js -D
  1. If you want to add react

    npm i eslint-plugin-react -D
    + const reactPlugin = require('eslint-plugin-react');
    + 
    module.exports = [
        js.configs.recommended, // eslint recommended
        eslintPluginPrettierRecommended, // prettier recommended
    +   reactPlugin.configs.flat.recommended, // This is not a plugin object, but a shareable config object
    +   reactPlugin.configs.flat['jsx-runtime'], // Add this if you are using React 17+

    Learn more

  2. If you want to add pre-commit hook to fix code style

    npm i husky lint-staged -D

    In package.json

    {
      "husky": {
        "hooks": {
          "pre-commit": "lint-staged"
        }
      },
      "lint-staged": {
        "*.js": [
          "eslint --fix"
        ]
      },
    }
const babelParser = require('@babel/eslint-parser');
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const js = require('@eslint/js');
const globals = require('globals');
module.exports = [
js.configs.recommended, // eslint recommended
eslintPluginPrettierRecommended, // prettier recommended
{
languageOptions: {
ecmaVersion: 2017,
sourceType: 'module',
parser: babelParser,
parserOptions: {
requireConfigFile: false,
babelOptions: {
babelrc: false,
configFile: false,
presets: ['@babel/preset-env']
}
},
globals: {
...globals.browser,
...globals.node,
defineComponent: true,
$: true,
Firmhouse: true,
Bugsnag: true
}
},
rules: {
'prettier/prettier': [
'error',
{
singleQuote: true,
jsxBracketSameLine: true,
trailingComma: 'none'
}
],
'no-console': 'off'
},
ignores: [
// only ignore node_modules in the same directory
// as the configuration file
'node_modules'
]
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment