Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESLint check #2438

Merged
merged 14 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/js-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- master
- 'feature/*'
- ESlint
pull_request:
branches:
- master
Expand All @@ -15,15 +16,20 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '14'
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Run eslint
run: npx eslint
continue-on-error: true

- name: Run JSLint
run: npx jslint "**/*.js"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
122 changes: 61 additions & 61 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
chrome.storage.local.get('limit_page_width', function (result) {
if (result.limit_page_width === false) {
chrome.storage.local.set({no_page_margin: true});
chrome.storage.local.remove(['limit_page_width'], (i) => {});

Check failure on line 88 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'i' is defined but never used
chrome.storage.local.get('player_size', function (r) {
if (r.player_size == 'full_window' || 'fit_to_window') {

Check failure on line 90 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Unexpected constant condition
chrome.storage.local.set({player_size: 'max_width'});
}
});
Expand Down Expand Up @@ -170,7 +170,7 @@
});
});
}
chrome.runtime.onInstalled.addListener(function (details) {

Check failure on line 173 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'details' is defined but never used
chrome.storage.local.get(function (items) {
var language = items.language;
updateContextMenu(language);
Expand Down Expand Up @@ -253,38 +253,38 @@
//console.log(sender);

switch(message.action || message.name || message) {
case 'play':
tabPrune(function () {
for (let id in tabConnected) {
id = Number(id);
if (id != sender.tab.id) {
chrome.tabs.sendMessage(id, {action: "another-video-started-playing"});
}
case 'play':
tabPrune(function () {
for (let id in tabConnected) {
id = Number(id);
if (id != sender.tab.id) {
chrome.tabs.sendMessage(id, {action: "another-video-started-playing"});
}
});
break
}
});
break

case 'options-page-connected':
sendResponse({
isTab: sender.hasOwnProperty('tab')
});
break
case 'options-page-connected':
sendResponse({
isTab: sender.hasOwnProperty('tab')

Check failure on line 269 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Do not access Object.prototype method 'hasOwnProperty' from target object
});
break

case 'tab-connected':
tabConnected[sender.tab.id] = true;
sendResponse({
tabId: sender.tab.id
});
break
case 'tab-connected':
tabConnected[sender.tab.id] = true;
sendResponse({
tabId: sender.tab.id
});
break

case 'fixPopup':
//~ get the current focused tab and convert it to a URL-less popup (with same state and size)
chrome.windows.getLastFocused(w => {
chrome.tabs.query({
windowId: w.id,
active: true
}, ts => {
const tID = ts[0]?.id,
case 'fixPopup':
//~ get the current focused tab and convert it to a URL-less popup (with same state and size)
chrome.windows.getLastFocused(w => {
chrome.tabs.query({
windowId: w.id,
active: true
}, ts => {
const tID = ts[0]?.id,
data = { type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
Expand All @@ -293,42 +293,42 @@
top: 20
}

if (tID) {data.tabId = tID;}
chrome.windows.create(data, pw => {});
if (tID) {data.tabId = tID;}
chrome.windows.create(data, pw => {});

Check failure on line 297 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'pw' is defined but never used

//append to title?
chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) {
if (tabId === tID && changeInfo.status === 'complete' && !message.title.startsWith("undefined")) {
chrome.tabs.onUpdated.removeListener(listener);
chrome.scripting.executeScript({ target: { tabId: tID }, func: () => { document.title = `${message.title} - ImprovedTube`; } }); //manifest3
// chrome.tabs.executeScript(tID, {code: `document.title = "${message.title} - ImprovedTube";`}); //manifest2
}
});
//append to title?
chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) {
if (tabId === tID && changeInfo.status === 'complete' && !message.title.startsWith("undefined")) {
chrome.tabs.onUpdated.removeListener(listener);
chrome.scripting.executeScript({ target: { tabId: tID }, func: () => { document.title = `${message.title} - ImprovedTube`; } }); //manifest3
// chrome.tabs.executeScript(tID, {code: `document.title = "${message.title} - ImprovedTube";`}); //manifest2
}
});
});
break
case 'download':
chrome.permissions.request({
permissions: ['downloads'],
origins: ['https://www.youtube.com/*']
}, function (granted) {
if (granted) {
try {
var blob = new Blob([JSON.stringify(message.value)], {
type: 'application/json;charset=utf-8'
});
chrome.downloads.download({
url: URL.createObjectURL(blob),
filename: message.filename,
saveAs: true
});
} catch (error) {
console.error(error);
}
} else {
console.error('Permission is not granted.');
}})
break
});
break
case 'download':
chrome.permissions.request({
permissions: ['downloads'],
origins: ['https://www.youtube.com/*']
}, function (granted) {
if (granted) {
try {
var blob = new Blob([JSON.stringify(message.value)], {
type: 'application/json;charset=utf-8'
});
chrome.downloads.download({
url: URL.createObjectURL(blob),
filename: message.filename,
saveAs: true
});
} catch (error) {
console.error(error);
}
} else {
console.error('Permission is not granted.');
}})
break
}
});
/*-----# UNINSTALL URL-----------------------------------*/
Expand Down
39 changes: 39 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("eslint:recommended"), {
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.webextensions,
...globals.jest,
...globals.worker,
...globals.wsh
}
},
rules: {
indent: ["error", "tab"],
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-unused-vars": ["error", { "caughtErrors": "none" }],
"no-undef": ["off"],
"max-len": ["error", {
code: 255,
ignoreUrls: true,
ignoreStrings: true,
ignoreComments: true,
ignoreRegExpLiterals: true
}]
}
}];
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
testPathIgnorePatterns: [
"/node_modules/"
],
testMatch: [
"**/tests/**/*.js"
]
testPathIgnorePatterns: [
"/node_modules/"
],
testMatch: [
"**/tests/**/*.js"
]
};
52 changes: 26 additions & 26 deletions js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,34 +180,34 @@
}

switch(message.type) {
case 'channel':
if (!extension.storage.data.blocklist.channels || typeof extension.storage.data.blocklist.channels !== 'object') {
extension.storage.data.blocklist.channels = {};
}
if (message.added) {
extension.storage.data.blocklist.channels[message.id] = {
title: message.title,
preview: message.preview,
when: message.when
}
} else {
delete extension.storage.data.blocklist.channels[message.id];
case 'channel':
if (!extension.storage.data.blocklist.channels || typeof extension.storage.data.blocklist.channels !== 'object') {
extension.storage.data.blocklist.channels = {};
}
if (message.added) {
extension.storage.data.blocklist.channels[message.id] = {
title: message.title,
preview: message.preview,
when: message.when
}
break
} else {
delete extension.storage.data.blocklist.channels[message.id];
}
break

case 'video':
if (!extension.storage.data.blocklist.videos || typeof extension.storage.data.blocklist.videos !== 'object') {
extension.storage.data.blocklist.videos = {};
}
if (message.added) {
extension.storage.data.blocklist.videos[message.id] = {
title: message.title,
when: message.when
}
} else {
delete extension.storage.data.blocklist.videos[message.id];
case 'video':
if (!extension.storage.data.blocklist.videos || typeof extension.storage.data.blocklist.videos !== 'object') {
extension.storage.data.blocklist.videos = {};
}
if (message.added) {
extension.storage.data.blocklist.videos[message.id] = {
title: message.title,
when: message.when
}
break
} else {
delete extension.storage.data.blocklist.videos[message.id];
}
break
}

chrome.storage.local.set({
Expand Down Expand Up @@ -241,8 +241,8 @@
}
});

document.addEventListener('it-play', function (event) {

Check failure on line 244 in js&css/extension/init.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'event' is defined but never used
var videos = document.querySelectorAll('video');

Check failure on line 245 in js&css/extension/init.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'videos' is assigned a value but never used
try {chrome.runtime.sendMessage({action: 'play'})}
catch(error){console.log(error); setTimeout(function () { try { chrome.runtime.sendMessage({action: 'play'}, function (response) { console.log(response) } ); } catch { } }, 321) }
catch(error){console.log(error); setTimeout(function () { try { chrome.runtime.sendMessage({action: 'play'}, function (response) { console.log(response) } ); } catch { } }, 321) }
});
Loading
Loading