Add eslint
This commit is contained in:
parent
abceb87436
commit
e56335dd45
25
.eslintrc.js
Normal file
25
.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
module.exports = {
|
||||||
|
'env': {
|
||||||
|
'browser': true,
|
||||||
|
'es2021': true,
|
||||||
|
},
|
||||||
|
'extends': 'google',
|
||||||
|
'overrides': [
|
||||||
|
{
|
||||||
|
'env': {
|
||||||
|
'node': true,
|
||||||
|
},
|
||||||
|
'files': [
|
||||||
|
'.eslintrc.{js,cjs}',
|
||||||
|
],
|
||||||
|
'parserOptions': {
|
||||||
|
'sourceType': 'script',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 'latest',
|
||||||
|
},
|
||||||
|
'rules': {
|
||||||
|
},
|
||||||
|
};
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
node_modules/
|
1125
package-lock.json
generated
Normal file
1125
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "gitea-conventional-comments-button",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "An extension to quickly add conventional comments",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"lint": "eslint src/**/*.js",
|
||||||
|
"lint_fix": "eslint --fix src/**/*.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/sebastian-sauer/gitea-conventional-comments-button.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"extension",
|
||||||
|
"gitea",
|
||||||
|
"conventional-comments"
|
||||||
|
],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/sebastian-sauer/gitea-conventional-comments-button/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/sebastian-sauer/gitea-conventional-comments-button#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^8.45.0",
|
||||||
|
"eslint-config-google": "^0.14.0"
|
||||||
|
}
|
||||||
|
}
|
@ -9,42 +9,42 @@ const stickyNoteIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448
|
|||||||
|
|
||||||
const semanticLabels = {
|
const semanticLabels = {
|
||||||
praise: {
|
praise: {
|
||||||
text: "praise",
|
text: 'praise',
|
||||||
icon: trophyIcon,
|
icon: trophyIcon,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
},
|
},
|
||||||
nitpick: {
|
nitpick: {
|
||||||
text: "nitpick",
|
text: 'nitpick',
|
||||||
icon: searchIcon,
|
icon: searchIcon,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
},
|
},
|
||||||
suggestion: {
|
suggestion: {
|
||||||
text: "suggestion",
|
text: 'suggestion',
|
||||||
icon: exclamationIcon,
|
icon: exclamationIcon,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
},
|
},
|
||||||
issue: {
|
issue: {
|
||||||
text: "issue",
|
text: 'issue',
|
||||||
icon: bugIcon,
|
icon: bugIcon,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
},
|
},
|
||||||
question: {
|
question: {
|
||||||
text: "question",
|
text: 'question',
|
||||||
icon: questionIcon,
|
icon: questionIcon,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
},
|
},
|
||||||
thought: {
|
thought: {
|
||||||
text: "thought",
|
text: 'thought',
|
||||||
icon: commentIcon,
|
icon: commentIcon,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
},
|
},
|
||||||
chore: {
|
chore: {
|
||||||
text: "chore",
|
text: 'chore',
|
||||||
icon: homeIcon,
|
icon: homeIcon,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
},
|
},
|
||||||
note: {
|
note: {
|
||||||
text: "note",
|
text: 'note',
|
||||||
icon: stickyNoteIcon,
|
icon: stickyNoteIcon,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
},
|
},
|
||||||
@ -63,22 +63,22 @@ const fillTextAreaValue = (textarea, value, emptySubject = true) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const semanticButtonClickHandler = (e, { textarea, label, blocking }) => {
|
const semanticButtonClickHandler = (e, {textarea, label, blocking}) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const decoration = blocking ? "" : " (non-blocking)";
|
const decoration = blocking ? '' : ' (non-blocking)';
|
||||||
const semanticComment = semanticCommentStructure
|
const semanticComment = semanticCommentStructure
|
||||||
.replace("%text", semanticLabels[label].text)
|
.replace('%text', semanticLabels[label].text)
|
||||||
.replace("%decoration", decoration);
|
.replace('%decoration', decoration);
|
||||||
const cleanedValue = textarea.value.replace(
|
const cleanedValue = textarea.value.replace(
|
||||||
/\*\*\w+(\s\(non-blocking\))?:\*\*\s?/,
|
/\*\*\w+(\s\(non-blocking\))?:\*\*\s?/,
|
||||||
""
|
'',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (cleanedValue && cleanedValue !== "<subject>") {
|
if (cleanedValue && cleanedValue !== '<subject>') {
|
||||||
fillTextAreaValue(
|
fillTextAreaValue(
|
||||||
textarea,
|
textarea,
|
||||||
semanticComment.replace(":** <subject>", `:** ${cleanedValue}`),
|
semanticComment.replace(':** <subject>', `:** ${cleanedValue}`),
|
||||||
false
|
false,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
fillTextAreaValue(textarea, semanticComment);
|
fillTextAreaValue(textarea, semanticComment);
|
||||||
@ -88,51 +88,52 @@ const semanticButtonClickHandler = (e, { textarea, label, blocking }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buttonGenerator = (textarea, parent, label, blocking) => {
|
const buttonGenerator = (textarea, parent, label, blocking) => {
|
||||||
const button = document.createElement("button");
|
const button = document.createElement('button');
|
||||||
button.setAttribute("data-tooltip-content", semanticLabels[label].text);
|
button.setAttribute('data-tooltip-content', semanticLabels[label].text);
|
||||||
button.innerHTML = semanticLabels[label].icon;
|
button.innerHTML = semanticLabels[label].icon;
|
||||||
|
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
button.classList.add("blocking");
|
button.classList.add('blocking');
|
||||||
button.setAttribute(
|
button.setAttribute(
|
||||||
"data-tooltip-content",
|
'data-tooltip-content',
|
||||||
`${semanticLabels[label].text} (blocking)`
|
`${semanticLabels[label].text} (blocking)`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
button.addEventListener("click", (e) =>
|
button.addEventListener('click', (e) =>
|
||||||
semanticButtonClickHandler(e, { textarea, label, blocking })
|
semanticButtonClickHandler(e, {textarea, label, blocking}),
|
||||||
);
|
);
|
||||||
parent.appendChild(button);
|
parent.appendChild(button);
|
||||||
};
|
};
|
||||||
|
|
||||||
const buttonPairGenerator = (textarea, parent, label) => {
|
const buttonPairGenerator = (textarea, parent, label) => {
|
||||||
const buttonContainer = document.createElement("div");
|
const buttonContainer = document.createElement('div');
|
||||||
buttonContainer.classList.add("buttonContainer");
|
buttonContainer.classList.add('buttonContainer');
|
||||||
buttonGenerator(textarea, buttonContainer, label, false);
|
buttonGenerator(textarea, buttonContainer, label, false);
|
||||||
if (semanticLabels[label].blocking) {
|
if (semanticLabels[label].blocking) {
|
||||||
buttonContainer.classList.add("hasBlockingButton");
|
buttonContainer.classList.add('hasBlockingButton');
|
||||||
buttonGenerator(textarea, buttonContainer, label, true);
|
buttonGenerator(textarea, buttonContainer, label, true);
|
||||||
}
|
}
|
||||||
parent.appendChild(buttonContainer);
|
parent.appendChild(buttonContainer);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addSemanticButton = (element) => {
|
const addSemanticButton = (elem) => {
|
||||||
const parent = element.querySelector('.field.footer');
|
const parent = elem.querySelector('.field.footer');
|
||||||
const container = document.createElement("div");
|
const container = document.createElement('div');
|
||||||
container.id = "conventionalCommentButtonContainer";
|
container.id = 'conventionalCommentButtonContainer';
|
||||||
container.classList.add("ui");
|
container.classList.add('ui');
|
||||||
container.classList.add("left");
|
container.classList.add('left');
|
||||||
Object.keys(semanticLabels).forEach((label) => {
|
Object.keys(semanticLabels).forEach((label) => {
|
||||||
buttonPairGenerator(element.querySelector('textarea.markdown-text-editor'), container, label);
|
const markdownEditor = elem.querySelector('textarea.markdown-text-editor');
|
||||||
|
buttonPairGenerator(markdownEditor, container, label);
|
||||||
});
|
});
|
||||||
parent.classList.remove("clearfix");
|
parent.classList.remove('clearfix');
|
||||||
parent.classList.add("has-conventional-comments-buttons");
|
parent.classList.add('has-conventional-comments-buttons');
|
||||||
parent.prepend(container);
|
parent.prepend(container);
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveChanges = (element) => {
|
const saveChanges = (element) => {
|
||||||
var event = new Event("input", {
|
const event = new Event('input', {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
});
|
});
|
||||||
@ -142,16 +143,17 @@ const saveChanges = (element) => {
|
|||||||
|
|
||||||
// Only add the interval if we're on the files diff page
|
// Only add the interval if we're on the files diff page
|
||||||
// (as on all other pages there is no need for conventional comments)
|
// (as on all other pages there is no need for conventional comments)
|
||||||
if(document.querySelector('.page-content.repository.view.issue.pull.files.diff')) {
|
const selector = '.page-content.repository.view.issue.pull.files.diff';
|
||||||
setInterval(function () {
|
if (document.querySelector(selector)) {
|
||||||
|
setInterval(function() {
|
||||||
document
|
document
|
||||||
.querySelectorAll(
|
.querySelectorAll(
|
||||||
".field.comment-code-cloud:not([data-semantic-button-initialized])"
|
'.field.comment-code-cloud:not([data-semantic-button-initialized])',
|
||||||
)
|
)
|
||||||
.forEach(function (note) {
|
.forEach(function(note) {
|
||||||
note.dataset.semanticButtonInitialized = "true";
|
note.dataset.semanticButtonInitialized = 'true';
|
||||||
note.querySelector('.markup-info').remove();
|
note.querySelector('.markup-info').remove();
|
||||||
addSemanticButton(note);
|
addSemanticButton(note);
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user