最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Eslint to warn when there is a missing import statement? - Stack Overflow

programmeradmin2浏览0评论

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.

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,
        'monjs': true,
        'es2021': true
    },
    'overrides': [
        {
            'files': ['*.ts'],
            'parserOptions': {
                'project': ['./tsconfig.json'],
            },
        }
    ],
    'extends': 'eslint:remended',
    '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'
    }
};

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.

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,
        'monjs': true,
        'es2021': true
    },
    'overrides': [
        {
            'files': ['*.ts'],
            'parserOptions': {
                'project': ['./tsconfig.json'],
            },
        }
    ],
    'extends': 'eslint:remended',
    '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'
    }
};

Share Improve this question asked May 14, 2022 at 5:11 Mike K.Mike K. 6063 gold badges23 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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

发布评论

评论列表(0)

  1. 暂无评论