CDLUC3 / dmsp_frontend_prototype

Repo to test out new NextJS framework
MIT License
0 stars 0 forks source link

Configure linting for app and correct existing issues #53

Closed jupiter007 closed 2 weeks ago

jupiter007 commented 4 weeks ago

We need to incorporate linting to catch JS and TypeScript errors.

As part of this ticket, we should fix existing issues, and run the "lint" script whenever a user wants to run a git commit (and possibly run "test" as well.

We should probably add a .eslintrc.js file that looks something like this:

module.exports = {
    parser: '@typescript-eslint/parser',
    parserOptions: {
        ecmaVersion: 2021,
        sourceType: 'module',
        ecmaFeatures: {
            jsx: true,
        },
    },
    env: {
        browser: true,
        es2021: true,
        node: true,
    },
    root: true,
    extends: [
        'next',
        'eslint:recommended',
        'next/core-web-vitals',
        'plugin:@typescript-eslint/recommended',
        'plugin:react/recommended',
    ],
    plugins: ['@typescript-eslint', 'react'],
    rules: {
        // JavaScript rules
        'prefer-const': 'warn',
        'no-var': 'warn',
        'no-unused-vars': 'warn',
        'object-shorthand': 'warn',
        'quote-props': ['warn', 'as-needed'],
        "react/react-in-jsx-scope": "off",
        // TypeScript rules
        '@typescript-eslint/array-type': [
            'warn',
            {
                default: 'array',
            },
        ],
        '@typescript-eslint/consistent-type-assertions': [
            'warn',
            {
                assertionStyle: 'as',
                objectLiteralTypeAssertions: 'never',
            },
        ],
    },
    settings: {
        react: {
            version: 'detect',
        },
    },
};

and an .eslintignore file.

Install @typescript-eslint/eslint-plugin, @typescript-eslint/parser, eslint-plugin-next