From 23fe5e01dbae29debae85e287d1f80c8548592f5 Mon Sep 17 00:00:00 2001 From: iampeterbanjo Date: Sun, 30 Oct 2016 13:04:47 +0100 Subject: [PATCH] create working extension with eslint configured locally --- eslint-example/.eslintrc.json | 8 ++++---- eslint-example/README.md | 4 +++- eslint-example/file.js | 14 +++----------- eslint-example/icons/LICENSE | 2 ++ eslint-example/icons/page-32.png | Bin 0 -> 344 bytes eslint-example/icons/page-48.png | Bin 0 -> 310 bytes eslint-example/main.js | 17 ++++++++++------ eslint-example/manifest.json | 19 ++++++++++++++++++ eslint-example/package.json | 32 ++++++++++++++++--------------- eslint-example/popup.html | 15 +++++++++++++++ 10 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 eslint-example/icons/LICENSE create mode 100644 eslint-example/icons/page-32.png create mode 100644 eslint-example/icons/page-48.png create mode 100644 eslint-example/manifest.json create mode 100644 eslint-example/popup.html diff --git a/eslint-example/.eslintrc.json b/eslint-example/.eslintrc.json index f589db7..8c8f0a2 100644 --- a/eslint-example/.eslintrc.json +++ b/eslint-example/.eslintrc.json @@ -2,11 +2,11 @@ "plugins": [ "mozilla" ], - "extends": [ - "eslint:recommended", - "plugin:mozilla" - ], + "rules": { "no-set-state": "off" + }, + "env": { + "es6": true } } \ No newline at end of file diff --git a/eslint-example/README.md b/eslint-example/README.md index fcfeed7..95a448d 100644 --- a/eslint-example/README.md +++ b/eslint-example/README.md @@ -2,4 +2,6 @@ ## What it shows -A project configured to use the [Mozilla ESlint configuration](https://www.npmjs.com/package/eslint-plugin-mozilla) \ No newline at end of file +A project configured to use the [Mozilla ESlint configuration](https://www.npmjs.com/package/eslint-plugin-mozilla) + +* to run locally configured eslint use `npm run lint` \ No newline at end of file diff --git a/eslint-example/file.js b/eslint-example/file.js index 830878b..b8a351f 100644 --- a/eslint-example/file.js +++ b/eslint-example/file.js @@ -1,12 +1,4 @@ -function getJSON(url, callback) { - let xhr = new XMLHttpRequest(); - xhr.onload = function() { - callback(this.responseText); - }; - xhr.open("GET", url, true); - xhr.send(); -} - -export function getUsefulContents(url, callback) { - getJSON(url, data => callback(JSON.parse(data))); +// we cant use export here +function getUsefulContents(callback) { + callback('Hello World'); } \ No newline at end of file diff --git a/eslint-example/icons/LICENSE b/eslint-example/icons/LICENSE new file mode 100644 index 0000000..20e821d --- /dev/null +++ b/eslint-example/icons/LICENSE @@ -0,0 +1,2 @@ + +The "page-32.png" and "page-48.png" icons are taken from the miu iconset created by Linh Pham Thi Dieu, and are used under the terms of its license: http://linhpham.me/miu/. diff --git a/eslint-example/icons/page-32.png b/eslint-example/icons/page-32.png new file mode 100644 index 0000000000000000000000000000000000000000..dae663dbb4989c607cb29de15c2d5300060c459d GIT binary patch literal 344 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq zxP?KOkzv*x383IFPZ!6Kh}O5)?7f%+1&)984`Ja~^yE|2Fx%-6#VyUBIMq6$fry* z{)J8Fd3GP*J~orN!QCe1*}CZ82Uh4?Y-tpd$}%(TVU<-8+kGtZ$xq&UR(}?6>*N%R z?OZ7x(RII8_N44~Um5j%-1W&1s|yC9yDm!jKi9ar+^ zNc`vx(*!cU_)S_JTgN^rL~;dB2%8r3)W%Z|sSAt*ZXekB?EQ`wKU1GS7wQxq3b@a* kp0>Z(uE>6;pio#-$q%07HSn)78&qol`;+0OH(%rvLx| literal 0 HcmV?d00001 diff --git a/eslint-example/icons/page-48.png b/eslint-example/icons/page-48.png new file mode 100644 index 0000000000000000000000000000000000000000..ba042cdcd5f88b6666d52e2ff60c3c963bc5ac35 GIT binary patch literal 310 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq zxP?KOkzv*x383H&PZ!6KjK;S!y}1rK2(Wq!+J}Fc($%%7d_v6O)^v&R%>f)IRW4U{ ztzR(xvhCEgduj>$=CgS?mNJ`NWD1;qzO;ARiRMMW)E+RcVNTn_+x2SpYo7^6LYO!$ z7+0@w46L<(?UCAP)_Cc7RMEeHU?;^14YnJ4L?lj6&g+crbqr*Re&G1?Sy!jf3Zrtn zgRV}IJr>c`+M5;I|5Y(J?~BN-t78@mcq|eGM9GY%eu^N3MIiVSo5+6-tCyP_)&7XR fz0 { - doSomethingUseful(data); - }); \ No newline at end of file + function start() { + getUsefulContents(data => { + var display = document.getElementById('display'); + + display.innerHTML = data; + }); + } + + document.addEventListener('DOMContentLoaded', start); \ No newline at end of file diff --git a/eslint-example/manifest.json b/eslint-example/manifest.json new file mode 100644 index 0000000..833787d --- /dev/null +++ b/eslint-example/manifest.json @@ -0,0 +1,19 @@ +{ + "manifest_version": 2, + "description": "Example using eslint", + "name": "eslint-example", + "version": "1.0", + "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/eslint-example", + + "applications": { + "gecko": { + "id": "eslint-example@mozilla.org", + "strict_min_version": "49.0" + } + }, + + "browser_action": { + "default_icon": "icons/page-32.png", + "default_popup": "popup.html" + } +} \ No newline at end of file diff --git a/eslint-example/package.json b/eslint-example/package.json index 6b77a47..77e5f4f 100644 --- a/eslint-example/package.json +++ b/eslint-example/package.json @@ -1,16 +1,18 @@ { - "name": "eslint-example", - "version": "1.0.0", - "description": "", - "main": "index.js", - "dependencies": {}, - "devDependencies": { - "eslint": "^3.9.0", - "eslint-plugin-mozilla": "^0.2.3" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC" -} + "name": "eslint-example", + "version": "1.0.0", + "description": "", + "main": "index.js", + "dependencies": {}, + "devDependencies": { + "eslint": "^3.9.0", + "eslint-plugin-mozilla": "^0.2.3" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "eslint": "./node_modules/.bin/eslint", + "lint": "eslint ." + }, + "author": "", + "license": "ISC" +} \ No newline at end of file diff --git a/eslint-example/popup.html b/eslint-example/popup.html new file mode 100644 index 0000000..92abfaa --- /dev/null +++ b/eslint-example/popup.html @@ -0,0 +1,15 @@ + + + + + Pop-up + + +

Example.com

+ +
+ + + + + \ No newline at end of file