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

Updating prettier and adding eslint #283

Draft
wants to merge 14 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.dccache
node_modules/
coverage/
android/
jest-coverage/
.nyc_output/
junit.xml
.idea/
.husky/
.github/
License.md
src-tauri/

.expo/
dist/
.env
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# playwright
/test-results/
/playwright-report/

# macOS
.DS_Store

.vercel

# eslint specific
package.json
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
extends: [
"universe",
"universe/native",
"universe/web",
"universe/shared/typescript-analysis",
],
overrides: [
{
files: ["*.ts", "*.tsx", "*.d.ts"],
parserOptions: {
project: "./tsconfig.json",
},
},
],
};
8 changes: 5 additions & 3 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ jobs:
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v3
- name: install dependencies
run: npm i
- name: Prettier Check
run: |
npm i [email protected]
npx prettier --check .
run: npx prettier --check .
- name: eslint check
run: npx eslint . --max-warnings=0

app_preview_dev:
if: ${{ contains(fromJSON('["pull_request"]'), github.event_name)}}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.dccache
node_modules/
coverage/
android/
jest-coverage/
.nyc_output/
junit.xml
Expand Down
27 changes: 2 additions & 25 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@

node_modules/
coverage/
jest-coverage/
.nyc_output/
junit.xml
.idea/
.husky/
# extends from .gitignore
.github/
License.md

.expo/
dist/
.env
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store

.vercel
src-tauri/
12 changes: 6 additions & 6 deletions app/Api/Drills.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { calculateNotes, sudokuStrategy, sudokuStrategyArray } from "sudokuru";
import { puzzle } from "./Puzzle.Types";
import { drill } from "./Puzzle.Types";
import { calculateNotes, sudokuStrategy } from "sudokuru";

import { puzzle, drill } from "./Puzzle.Types";
import { returnLocalDrillGame } from "../Functions/LocalDatabase";

/**
Expand All @@ -13,9 +13,9 @@ export class Drills {
* @returns a drill object corresponding to the drill type being requested.
*/
public static async getGame(strategy: sudokuStrategy): Promise<drill> {
let data: puzzle = returnLocalDrillGame(strategy);
let boardString: string = data.puzzle;
let notes: string = calculateNotes(boardString);
const data: puzzle = returnLocalDrillGame(strategy);
const boardString: string = data.puzzle;
const notes: string = calculateNotes(boardString);
return {
puzzleCurrentState: boardString,
puzzleCurrentNotesState: notes,
Expand Down
18 changes: 8 additions & 10 deletions app/Api/Lessons.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { sudokuStrategy } from "sudokuru";

export interface lessonOfflineMode {
mode: getLessonMode.Offline;
}
Expand All @@ -22,12 +20,12 @@ export class Lessons {
* @returns string array of strategy names that getSteps can be called with
*/
public static async getStrategies(
args: lessonOfflineMode | lessonOnlineMode
args: lessonOfflineMode | lessonOnlineMode,
): Promise<string[]> {
if (args.mode === getLessonMode.Online) {
const response: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/strategies.json",
{ cache: "no-cache" }
{ cache: "no-cache" },
);
const json = await response.json();
return json;
Expand All @@ -52,12 +50,12 @@ export class Lessons {
*/
public static async getSteps(
strategy: string,
args: lessonOfflineMode | lessonOnlineMode
args: lessonOfflineMode | lessonOnlineMode,
): Promise<string[][]> {
if (args.mode === getLessonMode.Online) {
const response: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/" + strategy + ".json",
{ cache: "no-cache" }
{ cache: "no-cache" },
);
const json = await response.json();
return json;
Expand Down Expand Up @@ -249,22 +247,22 @@ export class Lessons {
public static async getTutorial(): Promise<string[][]> {
const sudoku_101: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/SUDOKU_101.json",
{ cache: "no-cache" }
{ cache: "no-cache" },
);
const lesson1 = await sudoku_101.json();
const amend_notes: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/AMEND_NOTES.json",
{ cache: "no-cache" }
{ cache: "no-cache" },
);
const lesson2 = await amend_notes.json();
const naked_single = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/NAKED_SINGLE.json",
{ cache: "no-cache" }
{ cache: "no-cache" },
);
const lesson3 = await naked_single.json();
const simplify_notes = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/SIMPLIFY_NOTES.json",
{ cache: "no-cache" }
{ cache: "no-cache" },
);
const lesson4 = await simplify_notes.json();
const tutorial = lesson1.concat(lesson2, lesson3, lesson4);
Expand Down
6 changes: 3 additions & 3 deletions app/Api/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { getKeyJSON, storeData } from "../Functions/AsyncStorage";

export class Profile {
public static async getProfile(): Promise<profile> {
let value = await getKeyJSON("profile");
const value = await getKeyJSON("profile");
if (value == null) {
let profile: profile = {
const profile: profile = {
theme: true,
highlightBox: true,
highlightColumn: true,
Expand All @@ -23,7 +23,7 @@ export class Profile {
}

public static async setProfileValue(profileValue: string) {
let value: profile = await this.getProfile();
const value: profile = await this.getProfile();
if (profileValue === "theme") {
value.theme = !value.theme;
} else if (profileValue === "highlightBox") {
Expand Down
20 changes: 6 additions & 14 deletions app/Api/Puzzles.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { sudokuStrategyArray } from "sudokuru";
import { gameResults, puzzle, statistics } from "./Puzzle.Types";
import { activeGame } from "./Puzzle.Types";
import {
GameDifficulty,
GameDifficultyScore,
GameStatistics,
SudokuObjectProps,
returnLocalGame,
} from "../Functions/LocalDatabase";
import { getKeyJSON, removeData, storeData } from "../Functions/AsyncStorage";
import { puzzle, statistics } from "./Puzzle.Types";
import { Statistics } from "./Statistics";
import { getKeyJSON, removeData, storeData } from "../Functions/AsyncStorage";
import { SudokuObjectProps, returnLocalGame } from "../Functions/LocalDatabase";

// Random games to be used by getRandomGame for landing page
const DEMO_RANDOM_GAMES: puzzle[][] = [
Expand Down Expand Up @@ -225,13 +217,13 @@ export class Puzzles {
numHintsUsed: number,
numWrongCellsPlayed: number,
time: number,
score: number
score: number,
) {
// remove the game from storage
await removeData("active_game");

// Create or update user's statistics
let statistics: statistics = await Statistics.getStatistics();
const statistics: statistics = await Statistics.getStatistics();

statistics.totalScore += score;
if (
Expand All @@ -245,7 +237,7 @@ export class Puzzles {
statistics.numHintsUsed += numHintsUsed;
statistics.numWrongCellsPlayed += numWrongCellsPlayed;
statistics.averageSolveTime = Math.round(
statistics.totalSolveTime / statistics.numGamesPlayed
statistics.totalSolveTime / statistics.numGamesPlayed,
);

Statistics.saveStatisitics(statistics);
Expand Down
9 changes: 5 additions & 4 deletions app/Api/Statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export class Statistics {
* @returns promise of puzzle JSON object
*/
public static async getLearnedLessons(): Promise<JSON> {
let value = await getKeyJSON("learned_lessons");
const value = await getKeyJSON("learned_lessons");
// eslint-disable-next-line eqeqeq
if (value == undefined) {
return JSON.parse(JSON.stringify(["NONE"]));
} else {
Expand All @@ -22,7 +23,7 @@ export class Statistics {
public static async saveLearnedLessons(learnedLessons: string[]) {
// Removing NONE placeholder value if user has learned a lesson
if (learnedLessons.includes("NONE") && learnedLessons.length > 1) {
let index = learnedLessons.indexOf("NONE");
const index = learnedLessons.indexOf("NONE");
if (index !== -1) {
learnedLessons.splice(index, 1);
}
Expand All @@ -34,9 +35,9 @@ export class Statistics {
* returns all statistics objects for given user
*/
public static async getStatistics(): Promise<statistics> {
let value = await getKeyJSON("statistics");
const value = await getKeyJSON("statistics");
if (value == null) {
let statistics: statistics = {
const statistics: statistics = {
totalScore: 0,
numGamesPlayed: 0,
fastestSolveTime: 0,
Expand Down
7 changes: 4 additions & 3 deletions app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "@expo/metro-runtime"; // web fast refresh for development
import "react-native-gesture-handler"; // This needs to be at top to work
import { NavigationContainer } from "@react-navigation/native";
import { registerRootComponent } from "expo";
import * as React from "react";
import { PreferencesContext } from "./Contexts/PreferencesContext";
import { Provider as PaperProvider } from "react-native-paper";
import { NavigationContainer } from "@react-navigation/native";

import InitializeContext from "./Contexts/InitializeContext";
import { PreferencesContext } from "./Contexts/PreferencesContext";
import DrawerNavigator from "./Navigation/DrawerNavigator";
import { registerRootComponent } from "expo";

function App() {
const { theme, preferences } = InitializeContext();
Expand Down
21 changes: 11 additions & 10 deletions app/Components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useNavigation } from "@react-navigation/native";
import React from "react";
import ProfileButton from "./Profile/ProfileButton";
import StatisticsButton from "./Statistics/StatisticsButton";
import { Image, Pressable, View } from "react-native";
import { IconButton } from "react-native-paper";

import HomeButton from "./Home/HomeButton";
import { useNavigation } from "@react-navigation/native";
import ProfileButton from "./Profile/ProfileButton";
import StatisticsButton from "./Statistics/StatisticsButton";
import { PreferencesContext } from "../Contexts/PreferencesContext";
import { IconButton } from "react-native-paper";

const Header = () => {
const navigation: any = useNavigation();
Expand All @@ -16,7 +17,7 @@ const Header = () => {
const DARK_LOGO = require("../../.assets/goldLogoText.png");
const LIGHT_LOGO = require("../../.assets/darkBlueLogoText.png");

let logoUrl = isThemeDark ? DARK_LOGO : LIGHT_LOGO;
const logoUrl = isThemeDark ? DARK_LOGO : LIGHT_LOGO;

return (
<View
Expand All @@ -36,7 +37,7 @@ const Header = () => {
* If we are on the Landing page, Logo will not navigate to the Landing page
* If we are on any other page, Logo will navigate to the Landing page
*/
isCurrentPage == "Landing" ? (
isCurrentPage === "Landing" ? (
<Image
style={{
resizeMode: "cover",
Expand Down Expand Up @@ -70,16 +71,16 @@ const Header = () => {
justifyContent: "flex-end",
}}
>
{isCurrentPage == "No" ? (
{isCurrentPage === "No" ? (
<></>
) : isCurrentPage == "Statistics" ? (
) : isCurrentPage === "Statistics" ? (
<HomeButton />
) : (
<StatisticsButton />
)}
{isCurrentPage == "No" ? (
{isCurrentPage === "No" ? (
<></>
) : isCurrentPage == "Profile" ? (
) : isCurrentPage === "Profile" ? (
<HomeButton />
) : (
<ProfileButton />
Expand Down
Loading
Loading