Skip to content

Conversation

@latel
Copy link

@latel latel commented May 10, 2023

New features:

  • bumping up minor version for a new but compatible option

  • new option to disable browserslist support(to enforce no usages even though browsers are supported)

    rules: {
      'no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp': [
        'error',
        'no-lookahead',
     + { browserslist: false }
     ],
    }
    

Fixed:

  • fix browserslist feature, eg: currently plugin will report lookahead errors even though lookahead is supported
    image
    image
    image

Breaking Changes: none

okwang added 2 commits May 10, 2023 11:23
…feature

New features:
- new option to disable browserslist support

Fixed:
- fix browserslist feature, eg: report lookahead errors even though lookahead is supported

Breaking Changes:
- changed rule options format
@JonasBa
Copy link
Owner

JonasBa commented May 15, 2023

@latel instead of adding a new option, can we just check for browserslist config and enable it only if it is present?

@latel
Copy link
Author

latel commented May 16, 2023

@latel instead of adding a new option, can we just check for browserslist config and enable it only if it is present?

check for browserslist config and enable it only if it is present may not be a good idea, because too many toolchains like postcss and eslint-plugin-compat relies on it. we currently want an option to disable our plugin's browserslist support itself, at the same time, keep related toolchains works as well.

@JonasBa
Copy link
Owner

JonasBa commented May 16, 2023

@latel Ok, makes sense. The reasoning makes sense, the only thing I dislike about the PR is that it will require us to bump the package major version as the config has changed - this is something I would like to avoid. I propose that instead of breaking the config options and having to increment the package major, we allow users to pass an options object - since all other values are string types, we can type guard for {browserslist: true/false}. This will mean more work in the package, but we do not break compatibility.

The API would then look something like

'no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp': [
      'error',
      'no-lookbehind',
      'no-negative-lookbehind',
+     {browserslist: false}
   ],

The code in our plugin then checks for object shape and browserslist property and sets it to that value. I think this is more DX friendly and can ship as a minor version change so everyone can seamlessly upgrade.

Mea culpa on the initial API design... it probably should always have been an object.

Let me know if you have any thoughts on this.

P.S. if you do not have time to make this change it's totally understandable and I am happy to take over, just let me know, your contributions are much appreciated!

@latel
Copy link
Author

latel commented May 17, 2023

You are right, let's keep options compatible, your suggestions are always welcome

Copy link
Owner

@JonasBa JonasBa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏼, thank you for the contribution. I will publish a new version today!

import { noLookaheadLookbehindRegexp } from "./noLookaheadLookbehindRegex";

// Rule tester for when no browserlist is passed, so lookahead and lookbehind should not be allowed
// Rule tester for when no browserslist is passed, so lookahead and lookbehind should not be allowed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for also fixing my typos :)

@JonasBa JonasBa merged commit 6710c23 into JonasBa:main May 17, 2023
@JonasBa
Copy link
Owner

JonasBa commented May 17, 2023

I think this PR broke some functionality around negative lookbehind, I also just noticed that we copy the string literal for each node value which is not desirable as it can slowdown the plugin and increase memory usage

@latel
Copy link
Author

latel commented May 17, 2023

Do you have an actual broken case, let me digest it.

@JonasBa
Copy link
Owner

JonasBa commented May 17, 2023

Already fixed it, tldr, this was not reporting errors

@latel
Copy link
Author

latel commented May 18, 2023

This breaks the main fix in my PR, here is how to re-produce the case.

.eslintrc.js

module.exports = {
  env: {
    browser: true
  },
  extends: [
    'plugin:no-lookahead-lookbehind-regexp/recommended',
  ],
  rules: {
    'no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp': ['error', {
      browserslist: true
    }
    ],
  },
}

.browserslistrc

iOS >= 16.3

src/index.js

const behind = /aaa(?<=1)aaa/
const behindNegative = /bbb(?<!1)bbb/
const ahead = /ccc(?=1)ccc/
const aheadNegative = /ddd(?!1)ddd/
console.log(behind, behindNegative, ahead, aheadNegative)

running ./node_modules/.bin/eslint -c .eslintrc.js --debug src/index.js result in reporting following.

/Volumes/Code/play/webpack/src/index.js
  1:16  error  iOS Safari 16.3: unsupported lookbehind match group at position 3           no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp
  2:24  error  iOS Safari 16.3: unsupported negative lookbehind match group at position 3  no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp
  3:15  error  iOS Safari 16.3: unsupported lookahead match group at position 3            no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp
  4:23  error  iOS Safari 16.3: unsupported negative lookahead match group at position 3   no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp
  5:58  error  Newline required at end of file but not found

In fact, iOS 16.3 and above do support regex lookahead expression,
the plugin's depency caniuse-lite actually do not have a lookahead record, thus we should treat lookahead as always supported when the plugin's config.browserslist is set to true(default value)

@latel
Copy link
Author

latel commented May 22, 2023

😢

@JonasBa
Copy link
Owner

JonasBa commented May 22, 2023

@latel sorry I was off end of last week. Will look into this and fix it

@JonasBa
Copy link
Owner

JonasBa commented May 22, 2023

Ok, understood. I think this worked before because you were escaping the lookahead from being reported entirely, which should be a configurable option. I will look into it and make sure we have a fix asap

@JonasBa
Copy link
Owner

JonasBa commented May 23, 2023

@latel would you mind reviewing #6, I added the tests and I think it now works as expected, but a second pair of eyes would help.

Thanks for your patience!

@JonasBa
Copy link
Owner

JonasBa commented Jun 1, 2023

ping @latel if you have a moment to review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants