ghmcadams / vscode-lintlens

Augment your ESLint rules in Visual Studio Code - Adds metadata beside each ESLint rule.
MIT License
42 stars 9 forks source link

[Bug] False positives on uniqueness when passing a destructuring from a function #74

Open park-jemin opened 11 months ago

park-jemin commented 11 months ago

Seems the extension is unable to detect uniqueness when passing options from a function. There are a lot of cases where a custom function might be built to generate rules.

For example, per @typescript-eslint's recommendation on import/extensions:

function banImportExtension(extension) {
  const message = `Unexpected use of file extension (.${extension}) in import`;
  const literalAttributeMatcher = `Literal[value=/\\.${extension}$/]`;
  return [
    {
      // import foo from 'bar.js';
      selector: `ImportDeclaration > ${literalAttributeMatcher}.source`,
      message,
    },
    {
      // const foo = import('bar.js');
      selector: `ImportExpression > ${literalAttributeMatcher}.source`,
      message,
    },
    {
      // type Foo = typeof import('bar.js');
      selector: `TSImportType > TSLiteralType > ${literalAttributeMatcher}`,
      message,
    },
    {
      // const foo = require('foo.js');
      selector: `CallExpression[callee.name = "require"] > ${literalAttributeMatcher}.arguments`,
      message,
    },
  ];
}

module.exports = {
  // ... other config ...
  rules: {
    'no-restricted-syntax': [
      'error',
      ...banImportExtension('js'),
      ...banImportExtension('jsx'),
      ...banImportExtension('ts'),
      ...banImportExtension('tsx'),
    ],
  },
};

However, this gets flagged with the error options must have all unique items

Screenshot 2023-12-17 at 4 36 01 PM
ghmcadams commented 6 months ago

Thank you @park-jemin. Sorry for taking so long to respond. It is a challenge to support all of the many ways people could construct their configs. I tried to add support for the things I felt were a cross between easy to support and most likely to be used. This did not make the cut. Mostly because a function could be written in so many different ways to return valid or invalid config options. I am not that available at the moment, but if you can, please contribute to the code. I am willing to review and PR that comes my way.

Thank you