diff --git a/README.md b/README.md index ffcc4b3f..713838d8 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,6 @@ If your project doesn't use it or it is not installed in the same `package.json` } ``` -## Rules included in this repository - -Custom rules are currently wrapped in a locally-installed package. -This will no longer be needed once the eslint version used accepts objects as shown in -[custom rules tutorial](https://eslint.org/docs/latest/extend/custom-rule-tutorial#step-8-use-the-plugin-locally). - ## Changelog [View our up-to-date changelog](./CHANGELOG.md). diff --git a/eslint-plugin-skyscanner-no-axios/package.json b/eslint-plugin-skyscanner-no-axios/package.json deleted file mode 100644 index da215725..00000000 --- a/eslint-plugin-skyscanner-no-axios/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "main": "src/index.js" -} diff --git a/eslint-plugin-skyscanner-no-axios/src/index.js b/eslint-plugin-skyscanner-no-axios/src/index.js deleted file mode 100644 index 431ace0a..00000000 --- a/eslint-plugin-skyscanner-no-axios/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -const noAxios = require('./rules/no-axios'); - -module.exports = { - rules: { - 'no-axios': noAxios, - }, -}; diff --git a/eslint-plugin-skyscanner-no-axios/src/rules/no-axios.js b/eslint-plugin-skyscanner-no-axios/src/rules/no-axios.js deleted file mode 100644 index 7be3e30a..00000000 --- a/eslint-plugin-skyscanner-no-axios/src/rules/no-axios.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = { - create: (context) => ({ - CallExpression: (node) => { - if ( - node.callee.name === 'require' && - node.arguments.length > 0 && - typeof node.arguments[0].value === 'string' && - (node.arguments[0].value === 'axios' || - node.arguments[0].value.indexOf('axios/') === 0) - ) { - context.report(node, 'Deprecated require of axios package'); - } - }, - ImportDeclaration: (node) => { - if ( - node.source.value === 'axios' || - node.source.value.indexOf('axios/') === 0 - ) { - context.report(node, 'Deprecated import of axios package'); - } - }, - ImportExpression: (node) => { - if ( - typeof node.source.value === 'string' && - (node.source.value === 'axios' || - node.source.value.indexOf('axios/') === 0) - ) { - context.report(node, 'Deprecated import of axios package'); - } - }, - }), - meta: { - docs: { - description: - 'Deprecate the use of axios due to potential sensitive information leaks', - }, - type: 'problem', - }, -}; diff --git a/eslint-plugin-skyscanner-no-axios/src/rules/no-axios.test.js b/eslint-plugin-skyscanner-no-axios/src/rules/no-axios.test.js deleted file mode 100644 index fdcd76fe..00000000 --- a/eslint-plugin-skyscanner-no-axios/src/rules/no-axios.test.js +++ /dev/null @@ -1,112 +0,0 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -const { RuleTester } = require('eslint'); - -const noAxios = require('./no-axios'); - -const ruleTester = new RuleTester({ - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - }, -}); - -ruleTester.run('no-axios', noAxios, { - valid: [ - { - code: 'const test = require("foo-axios");', - }, - { - code: 'import test from "foo-axios";', - }, - { - // we can only detect actual strings, - // not string templates and other things that evaluate to string - code: 'const axios = await import(`axios`);', - }, - ], - invalid: [ - { - code: 'const axios = require("axios");', - errors: [ - { - message: 'Deprecated require of axios package', - }, - ], - }, - { - code: 'import axios from "axios";', - errors: [ - { - message: 'Deprecated import of axios package', - }, - ], - }, - { - code: 'const foo = require("axios/some/internal/thing");', - errors: [ - { - message: 'Deprecated require of axios package', - }, - ], - }, - { - code: 'import foo from "axios/some/internal/thing";', - errors: [ - { - message: 'Deprecated import of axios package', - }, - ], - }, - { - code: 'const { foo } = require("axios");', - errors: [ - { - message: 'Deprecated require of axios package', - }, - ], - }, - { - code: 'const foo = require("axios").default;', - errors: [ - { - message: 'Deprecated require of axios package', - }, - ], - }, - { - code: 'import { foo } from "axios";', - errors: [ - { - message: 'Deprecated import of axios package', - }, - ], - }, - - { - code: 'import("axios").then(() => console.log("foo"));', - errors: [ - { - message: 'Deprecated import of axios package', - }, - ], - }, - - { - code: 'const axios = await import("axios");', - errors: [ - { - message: 'Deprecated import of axios package', - }, - ], - }, - - { - code: 'import("axios").then(() => console.log("foo"));', - errors: [ - { - message: 'Deprecated import of axios package', - }, - ], - }, - ], -}); diff --git a/index.js b/index.js index 68ff8c43..262bc470 100644 --- a/index.js +++ b/index.js @@ -39,14 +39,14 @@ module.exports = { 'jest-formatting', 'sort-destructure-keys', 'typescript-enum', - 'skyscanner-no-axios', + '@skyscanner/rules', ], rules: { 'prettier/prettier': 'error', 'valid-jsdoc': ['error'], 'backpack/use-tokens': 'error', 'backpack/use-components': 'off', - 'skyscanner-no-axios/no-axios': 'error', + '@skyscanner/rules/no-axios': 'error', // This rule is pretty restrictive and we feel this decision should be left to developers to decide on a case by case basis. // A file can contain more than one class and still have a single responsibility diff --git a/package-lock.json b/package-lock.json index 74b4f1ae..ce5f3316 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@babel/core": "^7.23.7", "@babel/eslint-parser": "^7.23.3", "@babel/preset-react": "^7.23.3", + "@skyscanner/eslint-plugin-rules": "^1.0.1", "@typescript-eslint/eslint-plugin": "^6.19.0", "@typescript-eslint/parser": "^6.18.1", "colors": "^1.4.0", @@ -28,7 +29,6 @@ "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-skyscanner-no-axios": "file:./eslint-plugin-skyscanner-no-axios", "eslint-plugin-sort-destructure-keys": "^1.5.0", "eslint-plugin-typescript-enum": "^2.1.0", "prettier": "^3.2.4" @@ -54,7 +54,9 @@ "eslint": ">=8.0.0" } }, - "eslint-plugin-skyscanner-no-axios": {}, + "eslint-plugin-skyscanner-no-axios": { + "extraneous": true + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -1594,6 +1596,11 @@ "color": "^3.0.0" } }, + "node_modules/@skyscanner/eslint-plugin-rules": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@skyscanner/eslint-plugin-rules/-/eslint-plugin-rules-1.0.1.tgz", + "integrity": "sha512-vkQMNn6Fhbn1Lhh4d0Nq8fOIK4SUqgIxFYnScijqtrYHwUoTD3uQq4VhoiOzoQMMzjHvvutODHSZDRkMGXTVNQ==" + }, "node_modules/@types/babel__core": { "version": "7.20.2", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.2.tgz", @@ -4122,10 +4129,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/eslint-plugin-skyscanner-no-axios": { - "resolved": "eslint-plugin-skyscanner-no-axios", - "link": true - }, "node_modules/eslint-plugin-sort-destructure-keys": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/eslint-plugin-sort-destructure-keys/-/eslint-plugin-sort-destructure-keys-1.5.0.tgz", @@ -11247,6 +11250,11 @@ "color": "^3.0.0" } }, + "@skyscanner/eslint-plugin-rules": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@skyscanner/eslint-plugin-rules/-/eslint-plugin-rules-1.0.1.tgz", + "integrity": "sha512-vkQMNn6Fhbn1Lhh4d0Nq8fOIK4SUqgIxFYnScijqtrYHwUoTD3uQq4VhoiOzoQMMzjHvvutODHSZDRkMGXTVNQ==" + }, "@types/babel__core": { "version": "7.20.2", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.2.tgz", @@ -13129,9 +13137,6 @@ "integrity": "sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==", "requires": {} }, - "eslint-plugin-skyscanner-no-axios": { - "version": "file:eslint-plugin-skyscanner-no-axios" - }, "eslint-plugin-sort-destructure-keys": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/eslint-plugin-sort-destructure-keys/-/eslint-plugin-sort-destructure-keys-1.5.0.tgz", diff --git a/package.json b/package.json index 82fb4fff..f8e3a623 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@babel/core": "^7.23.7", "@babel/eslint-parser": "^7.23.3", "@babel/preset-react": "^7.23.3", + "@skyscanner/eslint-plugin-rules": "^1.0.1", "@typescript-eslint/eslint-plugin": "^6.19.0", "@typescript-eslint/parser": "^6.18.1", "colors": "^1.4.0", @@ -58,7 +59,6 @@ "eslint-plugin-import": "^2.29.1", "eslint-plugin-jest": "^27.6.3", "eslint-plugin-jest-formatting": "^3.1.0", - "eslint-plugin-skyscanner-no-axios": "file:./eslint-plugin-skyscanner-no-axios", "eslint-plugin-jsx-a11y": "^6.8.0", "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-react": "^7.33.2", diff --git a/test/package.json b/test/package.json index 5746a2c2..14ec1c6a 100644 --- a/test/package.json +++ b/test/package.json @@ -17,8 +17,7 @@ "test:fail-react": "echo 'Expecting failure' && eslint react-fail.tsx; if [ $? -eq 1 ]; then exit 0; fi", "test:fail-import-order": "echo 'Expecting failure' && eslint order-fail.jsx; if [ $? -eq 1 ]; then exit 0; fi", "test:fail-no-axios": "echo 'Expecting failure' && eslint no-axios-fail.jsx; if [ $? -eq 1 ]; then exit 0; fi", - "test:skyscanner-no-axios": "cd ../eslint-plugin-skyscanner-no-axios; jest", - "test": "npm run test:skyscanner-no-axios && npm run test:fail-no-axios && npm run test:pass && npm run test:fail-jsdoc && npm run test:fail-bpk && npm run test:fail-prettier && npm run test:fail-react && npm run test:fail-import-order" + "test": "npm run test:pass && npm run test:fail-no-axios &&npm run test:fail-jsdoc && npm run test:fail-bpk && npm run test:fail-prettier && npm run test:fail-react && npm run test:fail-import-order" }, "dependencies": { "prop-types": "^15.5.10",