-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #580 from Groww-OSS/feat/no-bucket-url-rule
Add no gcs bucket url eslint rule
- Loading branch information
Showing
6 changed files
with
9,998 additions
and
9,552 deletions.
There are no files selected for viewing
This file contains 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 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
26 changes: 26 additions & 0 deletions
26
packages/eslint-plugin-internal/lib/rules/no-gcs-bucket-url.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Disallow usage of GCS bucket URLs containing storage.googleapis.com", | ||
}, | ||
messages: { | ||
disallowedUrl: "Bucket URLs are disallowed. Use CDN URL instead.", | ||
}, | ||
}, | ||
|
||
create(context) { | ||
// Pattern to detect URLs containing 'storage.googleapis.com' | ||
const disallowedPattern = /https?:\/\/[^'"\s]*storage\.googleapis\.com[^'"\s]*/i; | ||
|
||
return { | ||
Literal(node) { | ||
if (typeof node.value === "string" && disallowedPattern.test(node.value)) { | ||
context.report({ | ||
node, // node to flag | ||
messageId: "disallowedUrl", // Error message | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains 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
25 changes: 25 additions & 0 deletions
25
packages/eslint-plugin-internal/tests/lib/rules/no-gcs-bucket-url.mjs
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { RuleTester } from "eslint"; | ||
|
||
import rule from "../../../lib/rules/no-gcs-bucket-url.js"; | ||
|
||
// Initialize the RuleTester with proper parserOptions | ||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 2021, | ||
sourceType: "module", | ||
}, | ||
}); | ||
|
||
// Define test cases for the rule | ||
ruleTester.run("no-gcs-bucket-url", rule, { | ||
valid: [ | ||
`const url = "https://cdn.example.com/bucket/file.jpg";` | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: `const url = "https://storage.googleapis.com/bucket/file.jpg";`, | ||
errors: [{ messageId: "disallowedUrl" }], | ||
}, | ||
], | ||
}); |
Oops, something went wrong.