From dc5d34f0f74bfd73a7dfa394bedbd69e123a5807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20L=C3=B6rincz?= Date: Mon, 1 May 2023 17:29:59 +0200 Subject: [PATCH] pretty print (#895) * added json for prettier, npm run prettier in lint-staged --- CONTRIBUTING.md | 1 + README-template.md | 1 - api-samples/contextMenus/basic/manifest.json | 2 +- .../no-cookies/manifest.json | 23 ++++++------- .../no-cookies/rules_1.json | 4 +-- .../url-blocker/manifest.json | 19 +++++------ .../url-blocker/rules_1.json | 10 +++--- .../url-redirect/manifest.json | 18 +++++----- .../url-redirect/rules_1.json | 30 ++++++++++------ api-samples/printing/README.md | 6 ++-- api-samples/scripting/manifest.json | 10 ++---- .../sample.catifier/manifest.json | 31 +++++++++-------- functional-samples/sample.catifier/rules.json | 34 ++++++++++++------- package.json | 4 +-- 14 files changed, 101 insertions(+), 92 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ddbfb055..52030ad0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,6 +46,7 @@ cd chrome-extensions-samples # install dependencies npm install ``` + ### Writing a README All new code samples or samples updated from Manifest V2 should include a README file. Please copy the [provided template](./README-template.md) into your sample's folder and follow the instructions therein. diff --git a/README-template.md b/README-template.md index 2cff1d2e..bad1550f 100644 --- a/README-template.md +++ b/README-template.md @@ -4,7 +4,6 @@ _To create a README for your sample_ 1. _Enter the requested information below._ 1. _Delete all intructions._ - _For API samples use the name of the API. For example, a sample about the `chrome.declarativeNetRequest` would simply be called "chrome.declarativeNetRequest". (Do not use special formatting in headings.) For functional samples, the title should be what the sample demonstrates_ # Title diff --git a/api-samples/contextMenus/basic/manifest.json b/api-samples/contextMenus/basic/manifest.json index fc46efa5..5a937470 100644 --- a/api-samples/contextMenus/basic/manifest.json +++ b/api-samples/contextMenus/basic/manifest.json @@ -4,7 +4,7 @@ "version": "0.7", "permissions": ["contextMenus"], "background": { - "service_worker": "sample.js" + "service_worker": "sample.js" }, "manifest_version": 3 } diff --git a/api-samples/declarativeNetRequest/no-cookies/manifest.json b/api-samples/declarativeNetRequest/no-cookies/manifest.json index 5c6d0896..062e04c8 100644 --- a/api-samples/declarativeNetRequest/no-cookies/manifest.json +++ b/api-samples/declarativeNetRequest/no-cookies/manifest.json @@ -3,21 +3,18 @@ "description": "Removes 'Cookie' headers.", "version": "1.0", "manifest_version": 3, - "permissions": [ - "declarativeNetRequest", - "declarativeNetRequestFeedback" - ], - "host_permissions": [ - "" - ], + "permissions": ["declarativeNetRequest", "declarativeNetRequestFeedback"], + "host_permissions": [""], "background": { "service_worker": "service-worker.js" }, - "declarative_net_request" : { - "rule_resources" : [{ - "id": "ruleset_1", - "enabled": true, - "path": "rules_1.json" - }] + "declarative_net_request": { + "rule_resources": [ + { + "id": "ruleset_1", + "enabled": true, + "path": "rules_1.json" + } + ] } } diff --git a/api-samples/declarativeNetRequest/no-cookies/rules_1.json b/api-samples/declarativeNetRequest/no-cookies/rules_1.json index fc5b5c0a..61c75d59 100644 --- a/api-samples/declarativeNetRequest/no-cookies/rules_1.json +++ b/api-samples/declarativeNetRequest/no-cookies/rules_1.json @@ -4,9 +4,7 @@ "priority": 1, "action": { "type": "modifyHeaders", - "requestHeaders": [ - { "header": "cookie", "operation": "remove" } - ] + "requestHeaders": [{ "header": "cookie", "operation": "remove" }] }, "condition": { "urlFilter": "|*?no-cookies=1", diff --git a/api-samples/declarativeNetRequest/url-blocker/manifest.json b/api-samples/declarativeNetRequest/url-blocker/manifest.json index b409159f..33682eb6 100644 --- a/api-samples/declarativeNetRequest/url-blocker/manifest.json +++ b/api-samples/declarativeNetRequest/url-blocker/manifest.json @@ -6,15 +6,14 @@ "background": { "service_worker": "service_worker.js" }, - "declarative_net_request" : { - "rule_resources" : [{ - "id": "ruleset_1", - "enabled": true, - "path": "rules_1.json" - }] + "declarative_net_request": { + "rule_resources": [ + { + "id": "ruleset_1", + "enabled": true, + "path": "rules_1.json" + } + ] }, - "permissions": [ - "declarativeNetRequest", - "declarativeNetRequestFeedback" - ] + "permissions": ["declarativeNetRequest", "declarativeNetRequestFeedback"] } diff --git a/api-samples/declarativeNetRequest/url-blocker/rules_1.json b/api-samples/declarativeNetRequest/url-blocker/rules_1.json index 5787d3dd..24908e50 100644 --- a/api-samples/declarativeNetRequest/url-blocker/rules_1.json +++ b/api-samples/declarativeNetRequest/url-blocker/rules_1.json @@ -1,11 +1,11 @@ [ { - "id" : 1, + "id": 1, "priority": 1, - "action" : { "type" : "block" }, - "condition" : { - "urlFilter" : "||example.com", - "resourceTypes" : ["main_frame"] + "action": { "type": "block" }, + "condition": { + "urlFilter": "||example.com", + "resourceTypes": ["main_frame"] } } ] diff --git a/api-samples/declarativeNetRequest/url-redirect/manifest.json b/api-samples/declarativeNetRequest/url-redirect/manifest.json index 9b307162..ff91e414 100644 --- a/api-samples/declarativeNetRequest/url-redirect/manifest.json +++ b/api-samples/declarativeNetRequest/url-redirect/manifest.json @@ -6,19 +6,19 @@ "background": { "service_worker": "service_worker.js" }, - "declarative_net_request" : { - "rule_resources" : [{ - "id": "ruleset_1", - "enabled": true, - "path": "rules_1.json" - }] + "declarative_net_request": { + "rule_resources": [ + { + "id": "ruleset_1", + "enabled": true, + "path": "rules_1.json" + } + ] }, "permissions": [ "declarativeNetRequest", "declarativeNetRequestFeedback", "declarativeNetRequestWithHostAccess" ], - "host_permissions": [ - "https://developer.chrome.com/" - ] + "host_permissions": ["https://developer.chrome.com/"] } diff --git a/api-samples/declarativeNetRequest/url-redirect/rules_1.json b/api-samples/declarativeNetRequest/url-redirect/rules_1.json index f3169dde..102fe5b3 100644 --- a/api-samples/declarativeNetRequest/url-redirect/rules_1.json +++ b/api-samples/declarativeNetRequest/url-redirect/rules_1.json @@ -1,10 +1,12 @@ [ { - "id" : 1, + "id": 1, "priority": 1, "action": { "type": "redirect", - "redirect": { "url": "https://developer.chrome.com/docs/extensions/mv3/intro/" } + "redirect": { + "url": "https://developer.chrome.com/docs/extensions/mv3/intro/" + } }, "condition": { "urlFilter": "https://developer.chrome.com/docs/extensions/mv2/", @@ -12,11 +14,13 @@ } }, { - "id" : 2, + "id": 2, "priority": 1, "action": { "type": "redirect", - "redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/action/" } + "redirect": { + "url": "https://developer.chrome.com/docs/extensions/reference/action/" + } }, "condition": { "urlFilter": "https://developer.chrome.com/docs/extensions/reference/browserAction/", @@ -24,11 +28,13 @@ } }, { - "id" : 3, + "id": 3, "priority": 1, "action": { "type": "redirect", - "redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/" } + "redirect": { + "url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/" + } }, "condition": { "urlFilter": "https://developer.chrome.com/docs/extensions/reference/declarativeWebRequest/", @@ -36,11 +42,13 @@ } }, { - "id" : 4, + "id": 4, "priority": 1, "action": { "type": "redirect", - "redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/action/" } + "redirect": { + "url": "https://developer.chrome.com/docs/extensions/reference/action/" + } }, "condition": { "urlFilter": "https://developer.chrome.com/docs/extensions/reference/pageAction/", @@ -48,11 +56,13 @@ } }, { - "id" : 5, + "id": 5, "priority": 1, "action": { "type": "redirect", - "redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/" } + "redirect": { + "url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/" + } }, "condition": { "urlFilter": "https://developer.chrome.com/docs/extensions/reference/webRequest/", diff --git a/api-samples/printing/README.md b/api-samples/printing/README.md index 51ee623f..70d6ca82 100644 --- a/api-samples/printing/README.md +++ b/api-samples/printing/README.md @@ -1,13 +1,13 @@ # chrome.printing -This sample demonstrates all four methods of the `chrome.printing` namespace. +This sample demonstrates all four methods of the `chrome.printing` namespace. ## Overview The `chrome.printing` namespace only works on ChromeOS. The sample demonstrates how to get a list of available printers and display it to a user. A 'Print' button sends a sample PDF to the selected printer and makes a 'Cancel Printing' visible. This button is visible while the print job's status is `"PENDING"` or `"IN_PROGRESS"`. Note that on some systems, the print job is passed to the printer so quickly that you may never see the 'Cancel Printing' button. -Calling `submitJob()` triggers a dialog box asking the user to confirm printing. Use the [`PrintingAPIExtensionsAllowlist`](https://chromeenterprise.google/policies/#PrintingAPIExtensionsAllowlist") policy to bypass confirmation. +Calling `submitJob()` triggers a dialog box asking the user to confirm printing. Use the [`PrintingAPIExtensionsAllowlist`](https://chromeenterprise.google/policies/#PrintingAPIExtensionsAllowlist") policy to bypass confirmation. ## Implementation Notes -Note that the `submitJob()` function throws an error when returning a promise ([crbug: 1422837](https://bugs.chromium.org/p/chromium/issues/detail?id=1422837)). +Note that the `submitJob()` function throws an error when returning a promise ([crbug: 1422837](https://bugs.chromium.org/p/chromium/issues/detail?id=1422837)). diff --git a/api-samples/scripting/manifest.json b/api-samples/scripting/manifest.json index 0a1e5a42..858f8277 100644 --- a/api-samples/scripting/manifest.json +++ b/api-samples/scripting/manifest.json @@ -5,13 +5,7 @@ "background": { "service_worker": "sw.js" }, - "permissions": [ - "scripting", - "webNavigation", - "storage" - ], - "host_permissions": [ - "https://example.com/*" - ], + "permissions": ["scripting", "webNavigation", "storage"], + "host_permissions": ["https://example.com/*"], "action": {} } diff --git a/functional-samples/sample.catifier/manifest.json b/functional-samples/sample.catifier/manifest.json index 239a2625..72737268 100644 --- a/functional-samples/sample.catifier/manifest.json +++ b/functional-samples/sample.catifier/manifest.json @@ -1,16 +1,17 @@ { - "name": "Catifier", - "version": "1.0", - "description": "Replace every image by a cat's image in a website you visit", - "permissions": ["declarativeNetRequest"], - "host_permissions": [""], - "declarative_net_request": { - "rule_resources": [{ - "id": "ruleset_1", - "enabled": true, - "path": "rules.json" - }] - }, - - "manifest_version": 3 - } \ No newline at end of file + "name": "Catifier", + "version": "1.0", + "description": "Replace every image by a cat's image in a website you visit", + "permissions": ["declarativeNetRequest"], + "host_permissions": [""], + "declarative_net_request": { + "rule_resources": [ + { + "id": "ruleset_1", + "enabled": true, + "path": "rules.json" + } + ] + }, + "manifest_version": 3 +} diff --git a/functional-samples/sample.catifier/rules.json b/functional-samples/sample.catifier/rules.json index feb8de0f..75d1409a 100644 --- a/functional-samples/sample.catifier/rules.json +++ b/functional-samples/sample.catifier/rules.json @@ -1,14 +1,24 @@ [ - { - "id": 1, - "priority": 100, - "action": { "type": "redirect", "redirect": { "url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg" } }, - "condition": {"urlFilter": "*.jpeg", "resourceType": ["image"]} + { + "id": 1, + "priority": 100, + "action": { + "type": "redirect", + "redirect": { + "url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg" + } }, - { - "id": 2, - "priority": 100, - "action": { "type": "redirect", "redirect": { "url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg" } }, - "condition": {"urlFilter": "*.jpg", "resourceType": ["image"]} - } - ] \ No newline at end of file + "condition": { "urlFilter": "*.jpeg", "resourceType": ["image"] } + }, + { + "id": 2, + "priority": 100, + "action": { + "type": "redirect", + "redirect": { + "url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg" + } + }, + "condition": { "urlFilter": "*.jpg", "resourceType": ["image"] } + } +] diff --git a/package.json b/package.json index 61648e3e..66c66479 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Official samples for Chrome Extensions and the Chrome Apps platform.", "scripts": { - "prettier": "npx prettier **/*.{md,html} -w", + "prettier": "npx prettier **/*.{md,html,json} -w", "lint": "eslint **/*.js", "lint:fix": "npm run lint -- --fix", "prepare": "husky install" @@ -33,7 +33,7 @@ "**/*.js": [ "npx eslint --fix" ], - "**/*.{md,html}": [ + "**/*.{md,html,json}": [ "npx prettier --write" ] }