Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARGG-857] Add rule forbidding the use of axios library #656

Merged
merged 14 commits into from
Dec 1, 2023

Conversation

soulcheck
Copy link
Contributor

What:
Adds a rule forbidding the use of axios library. The rule name is skyscanner-no-axios/no-axios

Why:
Axios is known to leak sensitive details in it's error objects

How:

  • Created a minimal eslint plugin package in a subfolder of the repo
  • Added a local install of that to the main package.json
  • Added the necessary config/

@soulcheck soulcheck added the minor label for minor changes label Nov 30, 2023
},
});

ruleTester.run('no-moment', noAxios, {
Copy link
Contributor

Choose a reason for hiding this comment

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

haha let's change to no-axios, otherwise all looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

{
"main": "src/index.js",
"peerDependencies": {
"eslint": "^8.53.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

this just means the eslint-config-skyscanner package needs to be on v8+, right?

Copy link
Contributor Author

@soulcheck soulcheck Nov 30, 2023

Choose a reason for hiding this comment

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

Yup. it's only used in the containing package. I would remove this requirement completely, but then eslint complains about a dependency that isn't listed (but is used in the rule)

context.report(node, 'Deprecated require of axios package');
}
},
ImportDeclaration: (node) => {
Copy link

Choose a reason for hiding this comment

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

very unlikely to happen but, does this cover dynamic imports? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added code to handle them. Had to bump the ES version to something that supports dynamic imports, left it at latest.

},
});

ruleTester.run('no-axios', noAxios, {
Copy link

Choose a reason for hiding this comment

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

I would also add a test for named imports and for requires with property access
require('axios').default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to add that. It should work though as the rule checks for the argument to require() call being axios - it doesn't care about what consumer does with result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a few tests more

@soulcheck soulcheck merged commit 828dfee into main Dec 1, 2023
3 checks passed
@soulcheck soulcheck deleted the ARGG-857_add_no_axios_rule branch December 1, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor label for minor changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants