create working extension with eslint configured locally

This commit is contained in:
iampeterbanjo
2016-10-30 13:04:47 +01:00
parent 4b96f89caa
commit 23fe5e01db
10 changed files with 74 additions and 37 deletions

View File

@@ -2,11 +2,11 @@
"plugins": [ "plugins": [
"mozilla" "mozilla"
], ],
"extends": [
"eslint:recommended",
"plugin:mozilla"
],
"rules": { "rules": {
"no-set-state": "off" "no-set-state": "off"
},
"env": {
"es6": true
} }
} }

View File

@@ -2,4 +2,6 @@
## What it shows ## What it shows
A project configured to use the [Mozilla ESlint configuration](https://www.npmjs.com/package/eslint-plugin-mozilla) 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`

View File

@@ -1,12 +1,4 @@
function getJSON(url, callback) { // we cant use export here
let xhr = new XMLHttpRequest(); function getUsefulContents(callback) {
xhr.onload = function() { callback('Hello World');
callback(this.responseText);
};
xhr.open("GET", url, true);
xhr.send();
}
export function getUsefulContents(url, callback) {
getJSON(url, data => callback(JSON.parse(data)));
} }

View File

@@ -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/.

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

View File

@@ -1,7 +1,12 @@
import { // not supported in Firefox
getUsefulContents // import { getUsefulContents } from "file";
} from "file";
getUsefulContents("http://www.example.com", data => { function start() {
doSomethingUseful(data); getUsefulContents(data => {
}); var display = document.getElementById('display');
display.innerHTML = data;
});
}
document.addEventListener('DOMContentLoaded', start);

View File

@@ -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"
}
}

View File

@@ -1,16 +1,18 @@
{ {
"name": "eslint-example", "name": "eslint-example",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"eslint": "^3.9.0", "eslint": "^3.9.0",
"eslint-plugin-mozilla": "^0.2.3" "eslint-plugin-mozilla": "^0.2.3"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
}, "eslint": "./node_modules/.bin/eslint",
"author": "", "lint": "eslint ."
"license": "ISC" },
} "author": "",
"license": "ISC"
}

15
eslint-example/popup.html Normal file
View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pop-up</title>
</head>
<body>
<h1 id="title">Example.com</h1>
<div id="display"></div>
<script src="file.js"></script>
<script src="main.js"></script>
</body>
</html>