-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Loosen apiClient ESLint rule on Security
#252212
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
Merged
steliosmavro
merged 6 commits into
elastic:main
from
steliosmavro:loosen-api-client-eslint-rule-on-security
Feb 11, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
269e67d
Loosen `apiClient` ESLint rule on Security
steliosmavro 49c3f13
Merge branch 'main' into loosen-api-client-eslint-rule-on-security
steliosmavro 329f8b9
Enhance with configurable option
steliosmavro 9d2c805
Address feedback
steliosmavro 6d6f29b
Merge branch 'main' into loosen-api-client-eslint-rule-on-security
steliosmavro a5ddb0d
Merge branch 'main' into loosen-api-client-eslint-rule-on-security
dmlemeshko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,10 @@ const { RuleTester } = require('eslint'); | |
| const rule = require('./scout_require_api_client_in_api_test'); | ||
| const dedent = require('dedent'); | ||
|
|
||
| const ERROR_MSG = | ||
| const DEFAULT_ERROR_MSG = | ||
| 'The `apiClient` fixture should be used in `apiTest` to call an endpoint and later verify response code and body.'; | ||
| const ALT_ERROR_MSG = | ||
| 'One of `apiClient` or `esClient` fixtures should be used in `apiTest` to interact with an endpoint and later verify the response.'; | ||
| const ruleTester = new RuleTester({ | ||
| parser: require.resolve('@typescript-eslint/parser'), | ||
| parserOptions: { | ||
|
|
@@ -161,7 +163,7 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| console.log(other); | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| // Nested apiTest inside apiTest.describe missing apiClient | ||
| { | ||
|
|
@@ -170,7 +172,7 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| apiTest('inner missing', () => {}); | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| // Nested blocks missing apiClient | ||
| { | ||
|
|
@@ -181,7 +183,7 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| } | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| // Nested helper function missing apiClient | ||
| { | ||
|
|
@@ -193,7 +195,7 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| helper(apiClient); | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| // Arrow function inside test | ||
| { | ||
|
|
@@ -202,7 +204,7 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| const callApi = () => apiClient.get('/bar'); | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| // External helper without apiClient usage | ||
| { | ||
|
|
@@ -214,7 +216,7 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| externalHelper(); | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| // Passing apiClient to a variable but never using it | ||
| { | ||
|
|
@@ -224,7 +226,50 @@ ruleTester.run('@kbn/eslint/scout_require_api_client_in_api_test', rule, { | |
| fn(apiClient); | ||
| }); | ||
| `, | ||
| errors: [{ message: ERROR_MSG }], | ||
| errors: [{ message: DEFAULT_ERROR_MSG }], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| // --- Tests with alternativeFixtures option --- | ||
| const altOptions = [{ alternativeFixtures: ['esClient'] }]; | ||
|
|
||
| ruleTester.run( | ||
| '@kbn/eslint/scout_require_api_client_in_api_test (with alternativeFixtures)', | ||
| rule, | ||
| { | ||
| valid: [ | ||
| // apiClient still accepted when alternativeFixtures is configured | ||
| { | ||
| code: dedent` | ||
| apiTest('uses apiClient', async ({ apiClient }) => { | ||
| await apiClient.get('/foo'); | ||
| }); | ||
| `, | ||
| options: altOptions, | ||
| }, | ||
| // Alternative fixture used instead of apiClient | ||
| { | ||
| code: dedent` | ||
| apiTest('uses esClient', async ({ esClient }) => { | ||
| await esClient.load('path/to/archive'); | ||
| }); | ||
|
Comment on lines
+253
to
+256
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| `, | ||
| options: altOptions, | ||
| }, | ||
| ], | ||
|
|
||
| invalid: [ | ||
| // Neither apiClient nor alternative fixture used | ||
| { | ||
| code: dedent` | ||
| apiTest('uses neither', async () => { | ||
| console.log('no fixture'); | ||
| }); | ||
| `, | ||
| options: altOptions, | ||
| errors: [{ message: ALT_ERROR_MSG }], | ||
| }, | ||
| ], | ||
| } | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I say "Security Solution" but
x-pack/platform/**/plugins/**/security/**/test/{scout,scout_*}/**/*.tsis not security solution - it's just a platform plugin, correct?If yes, do you have any better name suggestions for this section?
cc @dmlemeshko
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's allow it globally, it will be annoying to update
.eslintrc.jsevery time a new team decided to use onlyesClientfor api tests.As Sophie pointed out, it is totally fine to use
apiClientoresClientfor API tests when Teams think this what they want to do.