Mike K.
Mike K.

Reputation: 608

Eslint to warn when there is a missing import statement?

I'm using nodejs with regular javascript, and using eslint. My eslint is setup to catch many errors in my code - however it isn't catching when I forgot to import a package into my code. Below is one such example.

enter image description here

The rest of the eslint works where it will show red squigglies when something is wrong ... and I have it set so I can't do a deployment to production when errors exist. However it allows errors such as this.

Below is my current .eslint.rc file:

module.exports = {
    'env': {
        'browser': true,
        'commonjs': true,
        'es2021': true
    },
    'overrides': [
        {
            'files': ['*.ts'],
            'parserOptions': {
                'project': ['./tsconfig.json'],
            },
        }
    ],
    'extends': 'eslint:recommended',
    'parserOptions': {
        'ecmaVersion': 'latest'
    },
    'rules': {
        'arrow-body-style': 'off',
        'constructor-super': 'error',
        'curly': 'off',
        'dot-notation': 'off',
        'eol-last': 'error',
        'eqeqeq': [
            'error',
            'smart'
        ],
        'guard-for-in': 'off',
        'id-denylist': 'off',
        'id-match': 'off',
        'max-len': [
            'off',
            {
                'code': 140
            }
        ],
        'no-bitwise': 'error',
        'no-caller': 'error',
        'no-console': [
            'error',
            {
                'allow': [
                    'log',
                    'warn',
                    'info',
                    'dir',
                    'timeLog',
                    'assert',
                    'clear',
                    'count',
                    'countReset',
                    'group',
                    'groupEnd',
                    'table',
                    'dirxml',
                    'error',
                    'groupCollapsed',
                    'Console',
                    'profile',
                    'profileEnd',
                    'timeStamp',
                    'context'
                ]
            }
        ],
        'no-inner-declarations': 'off',
        'no-debugger': 'error',
        'no-empty': 'off',
        'no-empty-function': 'off',
        'no-eval': 'error',
        'no-fallthrough': 'error',
        'no-new-wrappers': 'error',
        'no-restricted-imports': [
            'error',
            'rxjs/Rx'
        ],
        'no-shadow': 'off',
        'no-throw-literal': 'error',
        // 'no-trailing-spaces': 'error',
        'no-undef': 'off',
        'no-undef-init': 'error',
        'no-underscore-dangle': 'off',
        'no-unused-expressions': 'error',
        'no-unused-labels': 'error',
        'no-var': 'error',
        'prefer-const': 'error',
        'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true, },],
        'semi': 'error'
    }
};

Upvotes: 1

Views: 4055

Answers (1)

user15211827
user15211827

Reputation: 61

Turn your no-undef rule on to error or warn.

Upvotes: 6

Related Questions