Skip to content

Commit

Permalink
Merge pull request #580 from Groww-OSS/feat/no-bucket-url-rule
Browse files Browse the repository at this point in the history
Add no gcs bucket url eslint rule
  • Loading branch information
saloni-groww authored Dec 13, 2024
2 parents 5dae4b0 + a244563 commit 16c23ac
Show file tree
Hide file tree
Showing 6 changed files with 9,998 additions and 9,552 deletions.
1 change: 1 addition & 0 deletions packages/eslint-config/eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@groww-tech/internal/prefer-type-alias": "warn",
"@groww-tech/internal/two-line-above-function": "warn",
"@groww-tech/internal/two-line-between-class-members": "warn",
"@groww-tech/internal/no-gcs-bucket-url": "error",
"quotes": [
"warn",
"single"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@groww-tech/eslint-config",
"version": "1.0.6",
"version": "1.0.7",
"description": "Standard Eslint config adopted in Groww. Customized as per requirement and preferences of devs in Groww.",
"main": "index.js",
"repository": {
Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-plugin-internal/lib/rules/no-gcs-bucket-url.js
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
});
}
},
};
},
};
2 changes: 1 addition & 1 deletion packages/eslint-plugin-internal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@groww-tech/eslint-plugin-internal",
"version": "1.0.4",
"version": "1.0.5",
"description": "ESLint Plugin with customized rules as per requirement and preferences of devs in Groww.",
"keywords": [
"eslint",
Expand Down
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" }],
},
],
});
Loading

0 comments on commit 16c23ac

Please sign in to comment.