Skip to content

Commit

Permalink
run prettier ./src --write (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdougie authored Aug 19, 2024
1 parent c1f0d1e commit bbadc20
Show file tree
Hide file tree
Showing 58 changed files with 1,429 additions and 1,003 deletions.
72 changes: 0 additions & 72 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module.exports = {
ignorePatterns: ["test", "dist", "build", "public", "/**/node_modules/*", ".eslintrc.js", "vite.config.ts", "vite-env.d.ts", "postcss.config.js", "tailwind.config.js", "vitest.config.ts", "playwright.config.ts", "e2e"],
rules: {
"indent": "off",
"@typescript-eslint/indent": "error",
// eslint:recommended
"arrow-body-style": ["error", "as-needed"],
curly: ["error", "all"],
Expand Down Expand Up @@ -122,15 +121,7 @@ module.exports = {
},
],
"array-bracket-newline": ["error", "consistent"],
"array-bracket-spacing": [
"error",
"never",
{
arraysInArrays: true,
},
],
"array-element-newline": ["error", "consistent"],
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": "error",
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs"],
Expand All @@ -148,7 +139,6 @@ module.exports = {
"eol-last": ["error", "always"],
"func-call-spacing": ["error", "never"],
"function-call-argument-newline": ["error", "consistent"],
"function-paren-newline": ["error", "multiline-arguments"],
"jsx-quotes": ["error", "prefer-double"],
"key-spacing": [
"error",
Expand All @@ -164,14 +154,6 @@ module.exports = {
after: true,
},
],
"line-comment-position": [
"error",
{
position: "above",
ignorePattern: "pragma",
applyDefaultIgnorePatterns: false,
},
],
"linebreak-style": ["error", "unix"],
"lines-around-comment": [
"error",
Expand All @@ -196,24 +178,10 @@ module.exports = {
exceptAfterSingleLine: true,
},
],
"multiline-ternary": ["error", "always-multiline"],
"new-parens": ["error", "never"],
"newline-per-chained-call": [
"error",
{
ignoreChainWithDepth: 2,
},
],
"no-multi-spaces": "error",
"no-multiple-empty-lines": "error",
"no-trailing-spaces": "error",
"no-whitespace-before-property": "error",
"object-curly-newline": [
"error",
{
multiline: true,
},
],
"object-curly-spacing": [
"error",
"always",
Expand All @@ -228,16 +196,6 @@ module.exports = {
allowAllPropertiesOnSameLine: true,
},
],
"operator-linebreak": [
"error",
"after",
{
overrides: {
"?": "before",
":": "before",
},
},
],
"padded-blocks": ["error", "never"],
"padding-line-between-statements": [
"error",
Expand Down Expand Up @@ -276,7 +234,6 @@ module.exports = {
],
"semi-style": ["error", "last"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"space-infix-ops": [
"error",
{
Expand Down Expand Up @@ -307,7 +264,6 @@ module.exports = {
functionPrototypeMethods: true,
},
],
"wrap-regex": "error",

// plugin:react/recommended
"react/destructuring-assignment": [
Expand Down Expand Up @@ -338,23 +294,10 @@ module.exports = {
"react/jsx-closing-bracket-location": "error",
"react/jsx-closing-tag-location": "error",
"react/jsx-curly-brace-presence": ["error", "never"],
"react/jsx-curly-newline": ["error", "consistent"],
"react/jsx-equals-spacing": ["error", "never"],
"react/jsx-first-prop-new-line": ["error", "multiline-multiprop"],
"react/jsx-fragments": ["error", "syntax"],
"react/jsx-indent-props": "off",
"react/jsx-max-props-per-line": [
"error",
{
maximum: 1,
},
],
"react/jsx-newline": [
"error",
{
prevent: false,
},
],
// "react/jsx-no-leaked-render": ["error", {
// "validStrategies": ["coerce"]
// }],
Expand All @@ -364,22 +307,7 @@ module.exports = {
allowExpressions: true,
},
],
"react/jsx-one-expression-per-line": [
"error",
{
allow: "literal",
},
],
"react/jsx-props-no-multi-spaces": "error",
"react/jsx-sort-props": [
"error",
{
callbacksLast: true,
shorthandFirst: true,
multiline: "last",
reservedFirst: true,
},
],
"react/jsx-tag-spacing": [
"error",
{
Expand Down
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"trailingComma": "all",
"tabWidth": 4,
"singleQuote": false
}
22 changes: 14 additions & 8 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// OpenSauced constants
export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env.VITE_OPEN_SAUCED_INSIGHTS_DOMAIN;
export const OPEN_SAUCED_API_ENDPOINT = import.meta.env.VITE_OPEN_SAUCED_API_ENDPOINT;
export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env
.VITE_OPEN_SAUCED_INSIGHTS_DOMAIN;
export const OPEN_SAUCED_API_ENDPOINT = import.meta.env
.VITE_OPEN_SAUCED_API_ENDPOINT;
export const REPO_QUERY_API_ENDPOINT = "https://opensauced.tools";
export const SUPABASE_LOGIN_URL = `https://${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}.supabase.co/auth/v1/authorize`;

Expand All @@ -14,7 +16,6 @@ export const OPEN_SAUCED_AUTH_TOKEN_KEY = "os-access-token";
export const OPEN_SAUCED_OPTED_LOG_OUT_KEY = "opted-log-out";
export const AI_PR_DESCRIPTION_CONFIG_KEY = "ai-pr-description-config";


export const OPEN_SAUCED_USERS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/users`;
export const OPEN_SAUCED_REPOS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/repos`;
export const OPEN_SAUCED_SESSION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/auth/session`;
Expand All @@ -29,12 +30,17 @@ export const OPEN_SAUCED_HIGHLIGHTS_LIST_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}
export const OPEN_SAUCED_EMOJIS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/emojis`;

// Content-scripts selectors
export const GITHUB_PROFILE_MENU_SELECTOR = ".p-nickname.vcard-username.d-block";
export const GITHUB_PROFILE_EDIT_MENU_CLASS = "button.js-profile-editable-edit-button";
export const GITHUB_PR_COMMENT_HEADER_CLASS = "timeline-comment-header clearfix d-flex";
export const GITHUB_REVIEW_SUGGESTION_CLASS = "js-suggestion-button-placeholder";
export const GITHUB_PROFILE_MENU_SELECTOR =
".p-nickname.vcard-username.d-block";
export const GITHUB_PROFILE_EDIT_MENU_CLASS =
"button.js-profile-editable-edit-button";
export const GITHUB_PR_COMMENT_HEADER_CLASS =
"timeline-comment-header clearfix d-flex";
export const GITHUB_REVIEW_SUGGESTION_CLASS =
"js-suggestion-button-placeholder";
export const GITHUB_REPO_ACTIONS_SELECTOR = ".pagehead-actions";
export const GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute = "[name='comment[body]']";
export const GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute =
"[name='comment[body]']";
export const GITHUB_PR_BASE_BRANCH_CLASS = "css-truncate css-truncate-target";
export const LINKEDIN_PROJECT_FORM_SELECTOR = ".artdeco-text-input--input";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { createHtmlElement } from "../../../utils/createHtmlElement";
import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg";
import { generateCodeExplanation, generateCodeSuggestion, generateCodeTest } from "../../../utils/ai-utils/openai";
import {
AICodeReviewMenu,
AICodeReviewMenuItem,
} from "./AICodeReviewMenu";

generateCodeExplanation,
generateCodeSuggestion,
generateCodeTest,
} from "../../../utils/ai-utils/openai";
import { AICodeReviewMenu, AICodeReviewMenuItem } from "./AICodeReviewMenu";

export const AICodeReviewButton = (commentNode: HTMLElement) => {
const changeSuggestorButton = createHtmlElement("a", {
innerHTML: `<span id="ai-change-gen" class="toolbar-item btn-octicon">
<img class="octicon octicon-heading" height="16px" width="16px" id="ai-description-button-logo" src=${chrome.runtime.getURL(
openSaucedLogoIcon,
)}>
openSaucedLogoIcon,
)}>
</span>`,
onclick: (event: MouseEvent) => {
event.stopPropagation();
Expand Down Expand Up @@ -45,5 +45,3 @@ export const AICodeReviewButton = (commentNode: HTMLElement) => {
changeSuggestorButton.append(menu);
return changeSuggestorButton;
};


29 changes: 20 additions & 9 deletions src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import {
DescriptionConfig,
getAIDescriptionConfig,
} from "../../../utils/ai-utils/descriptionconfig";
import { getAuthToken, isLoggedIn, optLogIn } from "../../../utils/checkAuthentication";
import {
getAuthToken,
isLoggedIn,
optLogIn,
} from "../../../utils/checkAuthentication";
import { createHtmlElement } from "../../../utils/createHtmlElement";
import { isOutOfContextBounds } from "../../../utils/fetchGithubAPIData";

type SuggestionGenerator = (
token: string,
code: string,
config: DescriptionConfig
config: DescriptionConfig,
) => Promise<string | undefined>;

export const AICodeReviewMenu = (items: HTMLLIElement[]) => {
Expand Down Expand Up @@ -39,15 +43,20 @@ export const AICodeReviewMenu = (items: HTMLLIElement[]) => {

menu.querySelector("ul")?.append(...items);

document.addEventListener("click", event => {
document.addEventListener("click", (event) => {
if (event.target instanceof HTMLElement) {
menu.classList.add("hidden");
}
});
return menu;
};

export const AICodeReviewMenuItem = (title: string, description: string, suggestionGenerator: SuggestionGenerator, commentNode: HTMLElement) => {
export const AICodeReviewMenuItem = (
title: string,
description: string,
suggestionGenerator: SuggestionGenerator,
commentNode: HTMLElement,
) => {
const menuItem = createHtmlElement("li", {
className: "SelectMenu-item d-block slash-command-menu-item",
role: "option",
Expand Down Expand Up @@ -90,7 +99,7 @@ const handleSubmit = async (
".code-review.selected-line",
);
let selectedCode = Array.from(selectedLines)
.map(line => line.textContent)
.map((line) => line.textContent)
.join("\n");

// find input with name="position" and get its value
Expand All @@ -100,15 +109,17 @@ const handleSubmit = async (
)!;
const position = positionElement.getAttribute("value")!;

const codeDiv = document.querySelector(`[data-line-number="${position}"]`)
?.nextSibling?.nextSibling as HTMLElement;
const codeDiv = document.querySelector(
`[data-line-number="${position}"]`,
)?.nextSibling?.nextSibling as HTMLElement;

selectedCode =
codeDiv.getElementsByClassName("blob-code-inner")[0].textContent!;
codeDiv.getElementsByClassName("blob-code-inner")[0]
.textContent!;
}
if (
isOutOfContextBounds(
[selectedCode, [] ],
[selectedCode, []],
descriptionConfig.config.maxInputLength,
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const AddPRToHighlightsButton = () => {
)}>
<details-menu id="details-menu-os" class="dropdown-menu hidden dropdown-menu-sw color-fg-default w-48 mt-2">
<a href="https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/feed?new=true&prurl=${encodeURIComponent(
window.location.href,
)}" class="dropdown-item" target="_blank">
window.location.href,
)}" class="dropdown-item" target="_blank">
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-plus">
<path d="M7.75 2a.75.75 0 0 1 .75.75V7h4.25a.75.75 0 0 1 0 1.5H8.5v4.25a.75.75 0 0 1-1.5 0V8.5H2.75a.75.75 0 0 1 0-1.5H7V2.75A.75.75 0 0 1 7.75 2Z"></path>
</svg> Add PR to Highlights
Expand All @@ -28,7 +28,7 @@ export const AddPRToHighlightsButton = () => {
},
});

addPRToHighlightsButton.addEventListener("click", e => {
addPRToHighlightsButton.addEventListener("click", (e) => {
e.stopPropagation();
});

Expand Down
Loading

0 comments on commit bbadc20

Please sign in to comment.