Skip to content

Commit 66b1ae3

Browse files
committed
Start using pre-commit and update eslint
1 parent 069fb75 commit 66b1ae3

9 files changed

+161
-104
lines changed

.eslintignore

-2
This file was deleted.

.eslintrc.json

-61
This file was deleted.

.github/workflows/build.yml

-26
This file was deleted.

.github/workflows/pre-commit.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
Build:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os:
13+
- ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v3
17+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
repos:
2+
3+
- repo: local
4+
hooks:
5+
6+
- id: eslint
7+
name: eslint
8+
entry: eslint
9+
language: node
10+
types_or:
11+
- javascript
12+
additional_dependencies:
13+
- "@eslint/[email protected]"
14+
- "@stylistic/[email protected]"
15+
16+
17+
18+
- id: translation-check
19+
name: translation-check
20+
entry: ./bin/translation-check
21+
language: system
22+
always_run: true
23+
24+
- id: tape
25+
name: tape
26+
entry: tape
27+
language: node
28+
files: .*test.*
29+
types_or:
30+
- javascript
31+
additional_dependencies:
32+
33+
34+
- id: web-ext lint
35+
name: web-ext lint
36+
entry: web-ext lint
37+
language: node
38+
types_or:
39+
- javascript
40+
pass_filenames: false
41+
additional_dependencies:
42+

background.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ browser.contextMenus?.onClicked.addListener(
255255

256256
function copyToClipboard(text) {
257257
chainPromises([
258-
() => { return browser.tabs.executeScript({ code: "typeof copyToClipboard === 'function';" }); },
258+
() => { return browser.tabs.executeScript({code: "typeof copyToClipboard === 'function';"}); },
259259
(results) => { return injectScriptIfNecessary(results && results[0]); },
260-
() => { return browser.tabs.executeScript({ code: `copyToClipboard("${text}")` }); },
260+
() => { return browser.tabs.executeScript({code: `copyToClipboard("${text}")`}); },
261261
]);
262262
}
263263

264264
function injectScriptIfNecessary(isCopyFunctionDefined) {
265265
if (!isCopyFunctionDefined) {
266-
return browser.tabs.executeScript({ file: "clipboard-helper.js" });
266+
return browser.tabs.executeScript({file: "clipboard-helper.js"});
267267
}
268268
}
269269

bin/translation-check

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ SCRIPT_DIRECTORY=$( cd "$( dirname "${BASH_SOURCE:-$0}" )" && pwd )
66
ROOT_DIRECTORY=$SCRIPT_DIRECTORY/..
77

88
REGEXP='browser.i18n.getMessage\("\K([^"]+)|"__MSG_\K([^_]+)|data-i18n="\K([^"]+)'
9-
FILES=$(find $ROOT_DIRECTORY -not -path '*node_modules*' -name '*.js*' -o -not -path '*node_modules*' -name '*.html')
109

11-
for language_directory in $ROOT_DIRECTORY/_locales/*
10+
for language_directory in "$ROOT_DIRECTORY"/_locales/*
1211
do
13-
echo $language_directory
12+
echo ""
13+
echo "$language_directory"
1414
diff \
1515
--unified \
16-
<(grep --perl-regexp --only-matching --no-filename $REGEXP $FILES 2>/dev/null | sort --unique) \
17-
<(jq --raw-output 'keys[]' $language_directory/messages.json) \
16+
<(grep --perl-regexp --only-matching --no-filename "$REGEXP" ./*.{js,json,html} options/*.{js,json,html} 2>/dev/null | sort --unique) \
17+
<(jq --raw-output 'keys[]' "$language_directory/messages.json") \
1818

1919
done

eslint.config.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const globals = require("globals");
2+
const js = require("@eslint/js");
3+
const stylistic = require("@stylistic/eslint-plugin-js");
4+
5+
module.exports = [
6+
{
7+
ignores: [
8+
"base64.js",
9+
"browser-polyfill.js",
10+
],
11+
languageOptions: {
12+
globals: {
13+
...globals.browser,
14+
...globals.commonjs,
15+
...globals.es6,
16+
...globals.jquery,
17+
...globals.webextensions,
18+
},
19+
parserOptions: {
20+
ecmaVersion: 2020,
21+
},
22+
},
23+
plugins: {
24+
stylistic: stylistic,
25+
},
26+
rules:{
27+
...js.configs.recommended.rules,
28+
"no-restricted-syntax": [
29+
"error",
30+
"ForInStatement",
31+
],
32+
"no-unused-vars": [
33+
"error",
34+
{
35+
"args": "all",
36+
"argsIgnorePattern": "^_[^_]",
37+
"varsIgnorePattern": "^_[^_]",
38+
},
39+
],
40+
"no-var": "error",
41+
"prefer-const": "error",
42+
"stylistic/array-bracket-newline": [
43+
"error",
44+
"consistent",
45+
],
46+
"stylistic/array-bracket-spacing": [
47+
"error",
48+
"never",
49+
],
50+
"stylistic/comma-dangle": [
51+
"error",
52+
{
53+
"arrays": "always-multiline",
54+
"exports": "always-multiline",
55+
"functions": "only-multiline",
56+
"imports": "always-multiline",
57+
"objects": "always-multiline",
58+
},
59+
],
60+
"stylistic/indent": [
61+
"error",
62+
4,
63+
{
64+
"SwitchCase": 1,
65+
},
66+
],
67+
"stylistic/linebreak-style": [
68+
"error",
69+
"unix",
70+
],
71+
"stylistic/no-console": [
72+
"off",
73+
],
74+
"stylistic/object-curly-spacing": [
75+
"error",
76+
"never",
77+
],
78+
"stylistic/quotes": [
79+
"error",
80+
"double",
81+
],
82+
"stylistic/semi": [
83+
"error",
84+
"always",
85+
],
86+
},
87+
},
88+
];

package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"author": "Sebastian Blask",
33
"devDependencies": {
4-
"eslint": "8.9.x",
5-
"tape": "5.5.x",
6-
"tape-benchmark": "0.0.0",
7-
"web-ext": "6.7.x"
4+
"@eslint/js": "^8.54.0",
5+
"@stylistic/eslint-plugin-js": "^1.4.0",
6+
"eslint": "^8.54.0",
7+
"tape": "^5.7.2",
8+
"web-ext": "^7.8.0"
89
},
910
"license": "MIT",
1011
"name": "skipredirect",
@@ -30,9 +31,7 @@
3031
"release": "VERSION=$(jq --raw-output '.version' manifest.json); hub release create $(for file in *$VERSION*.zip; do echo \" -a ${file} \"; done) -m $VERSION $VERSION",
3132
"start": "GTK_THEME=Greybird web-ext run --verbose --firefox firefox --url $(jq --raw-output '.homepage_url' manifest.json)",
3233
"start:german": "GTK_THEME=Greybird web-ext run --verbose --firefox firefox --pref=general.useragent.locale=de-DE --pref=intl.locale.matchOS=false --url $(jq --raw-output '.homepage_url' manifest.json)",
33-
"start:nightly": "GTK_THEME=Greybird web-ext run --verbose --firefox firefox-trunk --url $(jq --raw-output '.homepage_url' manifest.json)",
34-
"test": "web-ext lint && tape $(find . -not -path '*node_modules*' -name 'test-*.js') && npm run translation-check",
35-
"translation-check": "./bin/translation-check"
34+
"start:nightly": "GTK_THEME=Greybird web-ext run --verbose --firefox firefox-trunk --url $(jq --raw-output '.homepage_url' manifest.json)"
3635
},
3736
"title": "Skip Redirect",
3837
"version": "2.3.6"

0 commit comments

Comments
 (0)