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

Enforce .editorconfig using eslint #598

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ module.exports = {
},
plugins: ["react", "@typescript-eslint"],
rules: {
// silence some eslint:recommended rules
// TODO: Remove warn rules when not needed anymore
"no-self-assign": "off",
"@typescript-eslint/no-empty-interface": "off",

// .editorconfig:
"linebreak-style": ["error", "unix"],
"eol-last": "error",
"indent": ["error", 4],
},
settings: {
react: {
Expand Down
78 changes: 39 additions & 39 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,51 @@ if (utils.isFirefox()) {
}

chrome.tabs.onUpdated.addListener(function(tabId) {
chrome.tabs.sendMessage(tabId, {
chrome.tabs.sendMessage(tabId, {
message: 'update',
}, () => void chrome.runtime.lastError ); // Suppress error on Firefox
}, () => void chrome.runtime.lastError ); // Suppress error on Firefox
});

chrome.runtime.onMessage.addListener(function (request, sender, callback) {
switch(request.message) {
case "openConfig":
chrome.runtime.openOptionsPage();
return;
case "openHelp":
chrome.tabs.create({url: chrome.runtime.getURL('help/index_en.html')});
return;
case "sendRequest":
sendRequestToCustomServer(request.type, request.url, request.data).then(async (response) => {
callback({
responseText: await response.text(),
status: response.status,
ok: response.ok
});
switch(request.message) {
case "openConfig":
chrome.runtime.openOptionsPage();
return;
case "openHelp":
chrome.tabs.create({url: chrome.runtime.getURL('help/index_en.html')});
return;
case "sendRequest":
sendRequestToCustomServer(request.type, request.url, request.data).then(async (response) => {
callback({
responseText: await response.text(),
status: response.status,
ok: response.ok
});
});

return true;
case "submitVote":
submitVote(request.type, request.UUID, request.category).then(callback);
return true;
case "submitVote":
submitVote(request.type, request.UUID, request.category).then(callback);

//this allows the callback to be called later
return true;
case "alertPrevious":
if (Config.config.unsubmittedWarning) {
chrome.notifications.create("stillThere" + Math.random(), {
type: "basic",
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
message: chrome.i18n.getMessage("leftTimes"),
iconUrl: "./icons/LogoSponsorBlocker256px.png"
});
}
break;
case "registerContentScript":
registerFirefoxContentScript(request);
return false;
case "unregisterContentScript":
unregisterFirefoxContentScript(request.id)
return false;
}
//this allows the callback to be called later
return true;
case "alertPrevious":
if (Config.config.unsubmittedWarning) {
chrome.notifications.create("stillThere" + Math.random(), {
type: "basic",
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
message: chrome.i18n.getMessage("leftTimes"),
iconUrl: "./icons/LogoSponsorBlocker256px.png"
});
}
break;
case "registerContentScript":
registerFirefoxContentScript(request);
return false;
case "unregisterContentScript":
unregisterFirefoxContentScript(request.id)
return false;
}
});

//add help page on install
Expand Down Expand Up @@ -187,4 +187,4 @@ async function sendRequestToCustomServer(type: string, url: string, data = {}) {
});

return response;
}
}
4 changes: 2 additions & 2 deletions src/components/CategoryChooserComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CategoryChooserComponent extends React.Component<CategoryChooserProps, Cat
<tbody>
{/* Headers */}
<tr id={"CategoryOptionsRow"}
className="categoryTableElement categoryTableHeader">
className="categoryTableElement categoryTableHeader">
<td id={"CategoryOptionName"}>
{chrome.i18n.getMessage("category")}
</td>
Expand Down Expand Up @@ -68,4 +68,4 @@ class CategoryChooserComponent extends React.Component<CategoryChooserProps, Cat
}
}

export default CategoryChooserComponent;
export default CategoryChooserComponent;
54 changes: 27 additions & 27 deletions src/components/CategorySkipOptionsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
for (const categorySelection of Config.config.categorySelections) {
if (categorySelection.name === this.props.category) {
switch (categorySelection.option) {
case CategorySkipOption.ShowOverlay:
defaultOption = "showOverlay";
break;
case CategorySkipOption.ManualSkip:
defaultOption = "manualSkip";
break;
case CategorySkipOption.AutoSkip:
defaultOption = "autoSkip";
break;
case CategorySkipOption.ShowOverlay:
defaultOption = "showOverlay";
break;
case CategorySkipOption.ManualSkip:
defaultOption = "manualSkip";
break;
case CategorySkipOption.AutoSkip:
defaultOption = "autoSkip";
break;
}

break;
Expand All @@ -53,15 +53,15 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
className="categoryTableElement">
<td id={this.props.category + "OptionName"}
className="categoryTableLabel">
{chrome.i18n.getMessage("category_" + this.props.category)}
{chrome.i18n.getMessage("category_" + this.props.category)}
</td>

<td id={this.props.category + "SkipOption"}>
<select
className="categoryOptionsSelector"
defaultValue={defaultOption}
onChange={this.skipOptionSelected.bind(this)}>
{this.getCategorySkipOptions()}
{this.getCategorySkipOptions()}
</select>
</td>

Expand All @@ -85,10 +85,10 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr

<tr id={this.props.category + "DescriptionRow"}
className="small-description">
<td
colSpan={2}>
{chrome.i18n.getMessage("category_" + this.props.category + "_description")}
</td>
<td
colSpan={2}>
{chrome.i18n.getMessage("category_" + this.props.category + "_description")}
</td>
</tr>

</>
Expand All @@ -101,20 +101,20 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
this.removeCurrentCategorySelection();

switch (event.target.value) {
case "disable":
return;
case "showOverlay":
option = CategorySkipOption.ShowOverlay;
case "disable":
return;
case "showOverlay":
option = CategorySkipOption.ShowOverlay;

break;
case "manualSkip":
option = CategorySkipOption.ManualSkip;
break;
case "manualSkip":
option = CategorySkipOption.ManualSkip;

break;
case "autoSkip":
option = CategorySkipOption.AutoSkip;
break;
case "autoSkip":
option = CategorySkipOption.AutoSkip;

break;
break;
}

Config.config.categorySelections.push({
Expand Down Expand Up @@ -178,4 +178,4 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
}
}

export default CategorySkipOptionsComponent;
export default CategorySkipOptionsComponent;
4 changes: 2 additions & 2 deletions src/components/NoticeTextSectionComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class NoticeTextSelectionComponent extends React.Component<NoticeTextSelectionPr
onClick={this.props.onClick}
style={style}
className="sponsorTimesInfoMessage">
{this.props.text}
{this.props.text}
</p>
);
}
}

export default NoticeTextSelectionComponent;
export default NoticeTextSelectionComponent;
54 changes: 27 additions & 27 deletions src/components/SkipNoticeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
:

<td id={"sponsorTimesVoteButtonInfoMessage" + this.idSuffix}
className="sponsorTimesInfoMessage sponsorTimesVoteButtonMessage"
style={{marginRight: "10px"}}>
className="sponsorTimesInfoMessage sponsorTimesVoteButtonMessage"
style={{marginRight: "10px"}}>
{this.state.thanksForVotingText}
</td>
}
Expand Down Expand Up @@ -226,13 +226,13 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta

{/* Normal downvote */}
<button className="sponsorSkipObject sponsorSkipNoticeButton"
onClick={() => this.prepAction(SkipNoticeAction.Downvote)}>
onClick={() => this.prepAction(SkipNoticeAction.Downvote)}>
{chrome.i18n.getMessage("downvoteDescription")}
</button>

{/* Category vote */}
<button className="sponsorSkipObject sponsorSkipNoticeButton"
onClick={() => this.openCategoryChooser()}>
onClick={() => this.openCategoryChooser()}>

{chrome.i18n.getMessage("incorrectCategory")}
</button>
Expand All @@ -247,18 +247,18 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
<td>
{/* Category Selector */}
<select id={"sponsorTimeCategories" + this.idSuffix}
className="sponsorTimeCategories"
defaultValue={this.segments[0].category} //Just default to the first segment, as we don't know which they'll choose
ref={this.categoryOptionRef}
onChange={this.categorySelectionChange.bind(this)}>
className="sponsorTimeCategories"
defaultValue={this.segments[0].category} //Just default to the first segment, as we don't know which they'll choose
ref={this.categoryOptionRef}
onChange={this.categorySelectionChange.bind(this)}>

{this.getCategoryOptions()}
</select>

{/* Submit Button */}
{this.segments.length === 1 &&
<button className="sponsorSkipObject sponsorSkipNoticeButton"
onClick={() => this.prepAction(SkipNoticeAction.CategoryVote)}>
onClick={() => this.prepAction(SkipNoticeAction.CategoryVote)}>

{chrome.i18n.getMessage("submit")}
</button>
Expand Down Expand Up @@ -287,8 +287,8 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
for (let i = 0; i < this.segments.length; i++) {
elements.push(
<button className="sponsorSkipObject sponsorSkipNoticeButton"
onClick={() => this.performAction(i)}
key={"submission" + i + this.segments[i].category + this.idSuffix}>
onClick={() => this.performAction(i)}
key={"submission" + i + this.segments[i].category + this.idSuffix}>
{(i + 1) + ". " + chrome.i18n.getMessage("category_" + this.segments[i].category)}
</button>
);
Expand Down Expand Up @@ -339,20 +339,20 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
*/
performAction(index: number, action?: SkipNoticeAction): void {
switch (action ?? this.state.actionState) {
case SkipNoticeAction.None:
break;
case SkipNoticeAction.Upvote:
this.contentContainer().vote(1, this.segments[index].UUID, undefined, this);
break;
case SkipNoticeAction.Downvote:
this.contentContainer().vote(0, this.segments[index].UUID, undefined, this);
break;
case SkipNoticeAction.CategoryVote:
this.contentContainer().vote(undefined, this.segments[index].UUID, this.categoryOptionRef.current.value, this)
break;
case SkipNoticeAction.Unskip:
this.state.unskipCallback(index);
break;
case SkipNoticeAction.None:
break;
case SkipNoticeAction.Upvote:
this.contentContainer().vote(1, this.segments[index].UUID, undefined, this);
break;
case SkipNoticeAction.Downvote:
this.contentContainer().vote(0, this.segments[index].UUID, undefined, this);
break;
case SkipNoticeAction.CategoryVote:
this.contentContainer().vote(undefined, this.segments[index].UUID, this.categoryOptionRef.current.value, this)
break;
case SkipNoticeAction.Unskip:
this.state.unskipCallback(index);
break;
}

this.setState({
Expand Down Expand Up @@ -398,7 +398,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
for (const category of Config.config.categorySelections) {
elements.push(
<option value={category.name}
key={category.name}>
key={category.name}>
{chrome.i18n.getMessage("category_" + category.name)}
</option>
);
Expand All @@ -408,7 +408,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
// Add show more button
elements.push(
<option value={"moreCategories"}
key={"moreCategories"}>
key={"moreCategories"}>
{chrome.i18n.getMessage("moreCategories")}
</option>
);
Expand Down