amilajack / eslint-plugin-compat

Check the browser compatibility of your code
MIT License
3.07k stars 104 forks source link

Lookbehind in regular expressions not reported even though it is not supported on Safari browser #555

Open Zhouqchao opened 1 year ago

Zhouqchao commented 1 year ago

lookbehind in regular expresions should report an error because it is not supported on Safari browser. image

here is my browserslist config:

{
    "browserslist": [
        "last 2 years",
        "not dead"
      ]
}

and here is my eslint config:

module.exports = {
    root: true,
    env: {
      browser: true,
    },
    plugins: ['compat'],
    settings: {
      lintAllEsApis: true,
    },
    extends: ['plugin:compat/recommended'],
    parserOptions: {
      ecmaVersion: 2018,
      parser: 'babel-eslint',
      sourceType: 'module',
    },
    rules: {
      'compat/compat': 'error',
    }
}

I do get an error for OffscreenCanvas not being supported on Safari 14, so it looks like I have set up the plugin correctly. image

MrHBS commented 1 year ago

I was literally about to install this plugin to lint for this use case. This is a bummer

RobinBlomberg commented 3 months ago

For a basic workaround (that unfortunately doesn't take Browserslist settings into account):

rules: {
  "no-restricted-syntax": [
    "error",
    {
      selector: "Literal[regex][raw=/\\(\\?<[=!]/]",
      message:
        "Lookbehind assertions are not supported in some browsers (e.g. Safari 16.3).",
    },
  ],
},