eslint-community / eslint-plugin-security

ESLint rules for Node Security
Apache License 2.0
2.22k stars 109 forks source link

ESLint v9 compatibility (TypeError: context.getScope is not a function) #144

Closed rivajunior closed 7 months ago

rivajunior commented 7 months ago

What version of eslint-plugin-security are you using?

2.1.1

ESLint Environment

Node version: v20.12.1 npm version: 10.5.0 Local ESLint version: v9.0.0 Global ESLint version: - Operating System: MacOS 14.4.1

What parser are you using?

@typescript-eslint/parser

What did you do?

Configuration ``` ```
<!-- Paste your code here -->

What did you expect to happen?

I expected the lint to run without errors

What actually happened?

Oops! Something went wrong! :(

ESLint: 9.0.0

TypeError: context.getScope is not a function
Occurred while linting /my/project/path/banner.ts:13
Rule: "security/detect-child-process"
    at CallExpression (/my/project/path/node_modules/eslint-plugin-security/rules/detect-child-process.js:49:28)
    at ruleErrorHandler (/my/project/path/node_modules/eslint/lib/linter/linter.js:1145:48)
    at /my/project/path/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/my/project/path/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/my/project/path/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/my/project/path/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/my/project/path/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at runRules (/my/project/path/node_modules/eslint/lib/linter/linter.js:1184:40)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/my/project/path/node_modules/eslint/lib/linter/linter.js:1910:31)

Participation

Additional comments

No response

nzakas commented 7 months ago

Thanks for the report, I'll take a look.

dmitriyrotaenko commented 6 months ago

The problem is still alive in eslint ^9.2.0. Should I open another issue?

aladdin-add commented 6 months ago

@dmitriyrotaenko please file a new issue with a repro, thanks! 🙏

AlwaysLoveme commented 6 months ago

The problem is still alive in eslint ^9.2.0. Should I open another issue?

same here:

eslint.config.js:

// @ts-check

import globals from "globals";
import pluginJs from "@eslint/js";
import tsLint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";

export default tsLint.config(
        {
            languageOptions: {
                globals: {...globals.browser, ...globals.node}
            }
        },
        pluginJs.configs.recommended,
        ...tsLint.configs.recommended,
        pluginReactConfig,
        {
            plugins: ["react", 'react-refresh'],
            files: ["**/*.tsx", "**/*.ts"],
            rules: {
                'react/require-render-return': 'off',
                'react-refresh/only-export-components': [
                    'warn',
                    {allowConstantExport: true},
                ],
                "@typescript-eslint/ban-ts-comment": "off",
                "@typescript-eslint/no-explicit-any": "off",
                "@typescript-eslint/no-unused-vars": "off",
                "@typescript-eslint/no-var-requires": "off",
                "semi": ["error", "always"], // 强制末尾分号
                "quotes": ["error", "double", {allowTemplateLiterals: true}],
                "@next/next/no-img-element": "off",
                "eqeqeq": "error", // 要求使用 === 和 !==
                "no-empty": "error", // 块语句中的内容不能为空
                "no-empty-character-class": "error", // 正则表达式中的[]内容不能为空
                "no-extra-boolean-cast": "error", // 禁止不必要的bool转换
                "no-extra-parens": "off", // 禁止非必要的括号
                "no-extra-semi": "error", // 禁止多余的冒号
                "no-invalid-this": "error", // 禁止无效的this,只能用在构造器,类,对象字面量
                "no-irregular-whitespace": "error", // 不能有不规则的空格
                "no-self-assign": "error", // 禁止自我赋值
                "no-self-compare": "error", // 禁止自身比较
                "no-sequences": "error", // 禁用逗号操作符
                "key-spacing": ["error", {beforeColon: false, afterColon: true}], // 对象字面量中冒号的前后空格
                "no-unmodified-loop-condition": "error", // 禁用一成不变的循环条件
                "no-unused-expressions": "off", // 禁止出现未使用过的表达式
                "object-curly-spacing": ["error", "always"], // 对象前后需要空格
                "array-bracket-spacing": [
                    "error",
                    "never",
                    {
                        objectsInArrays: false,
                    },
                ], // 是否允许非空数组里面有多余的空格
                "arrow-parens": "off", // 箭头函数用小括号括起来
                "block-spacing": ["error", "always"], // =>的前/后括号
                "callback-return": "off", // 避免多次调用回调
                "react/self-closing-comp": [
                    "error",
                    {
                        component: true,
                        html: false,
                    },
                ],
                "react/react-in-jsx-scope": "off",
                "react/jsx-closing-tag-location": ["error"],
                "react/jsx-first-prop-new-line": ["error", "multiline-multiprop"],
                "react/jsx-closing-bracket-location": ["error"],
                "react/jsx-max-props-per-line": ["error", {maximum: 1, when: "always"}],
                "react/jsx-wrap-multilines": [
                    "error",
                    {
                        declaration: true,
                        assignment: true,
                        return: true,
                        arrow: true,
                        condition: true,
                    },
                ],
                "react/jsx-sort-props": [
                    "error",
                    {
                        multiline: "last",
                        callbacksLast: true,
                        shorthandFirst: true,
                    },
                ],
                'react/jsx-no-undef': ['error', {allowGlobals: true}],
                "react-hooks/exhaustive-deps": ["off"],
            }
        }
);
nzakas commented 6 months ago

This has nothing to do with the version of ESLint. Please make sure you have upgraded your eslint-plugin-security to latest.

flowerhahaha commented 6 months ago

I got the same issue, and I didn't use eslint-plugin-security in my project.
I've upgraded all the related packages to the latest and the problem still alive. Any suggestions? Thanks a lot.

jmaczan commented 6 months ago

I get the same error when running eslint src/**/*.{js,jsx,ts,tsx}

Deps:

    "@eslint/js": "^9.2.0",
    "eslint": "^9.2.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.1.3",
    "eslint-plugin-react": "^7.34.1",
nzakas commented 6 months ago

Okay, it seems like people are a bit confused: this repository is only for eslint-plugin-security. If you're not using eslint-plugin-security, then you need to file an issue with the owner of the plugin you're having trouble with.