-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from 2anki/refactor/code-smells
enable: eslint action
- Loading branch information
Showing
243 changed files
with
11,762 additions
and
8,217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ['airbnb-typescript', 'prettier'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: './tsconfig.json', | ||
}, | ||
plugins: ['import', '@typescript-eslint', 'prettier'], | ||
rules: { | ||
'react/jsx-filename-extension': 'off', | ||
'prettier/prettier': ['error'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx pretty-quick --staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"printWidth": 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Knex } from "knex"; | ||
import { Knex } from 'knex'; | ||
|
||
export default function getEmailFromOwner(DB: Knex, id: string) { | ||
return DB("users").where({ id }).returning(["email"]).first(); | ||
return DB('users').where({ id }).returning(['email']).first(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { Knex } from "knex"; | ||
import { Knex } from 'knex'; | ||
|
||
export default function getOwnerFromAccessToken(DB: Knex, token: string) { | ||
return DB("access_tokens") | ||
.where({ token, host: "2anki.net" }) | ||
.returning(["owner"]) | ||
return DB('access_tokens') | ||
.where({ token, host: '2anki.net' }) | ||
.returning(['owner']) | ||
.first(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Knex } from "knex"; | ||
import { Knex } from 'knex'; | ||
|
||
export default function isPatron(DB: Knex, id: string) { | ||
return DB("users").where({ id }).returning(["patreon"]).first(); | ||
return DB('users').where({ id }).returning(['patreon']).first(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Knex } from "knex"; | ||
import { Knex } from 'knex'; | ||
|
||
import hashPassword from "./hashPassword"; | ||
import hashPassword from './hashPassword'; | ||
|
||
export default async function updatePassword( | ||
DB: Knex, | ||
password: any, | ||
reset_token: any | ||
) { | ||
return DB("users") | ||
return DB('users') | ||
.where({ reset_token }) | ||
.update({ password: hashPassword(password), reset_token: null }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
/** | ||
* This will collapse children with exact same title to the parent. | ||
* This is safe to do because the parent will be the one that is used to create the deck. | ||
* This is safe to do because the parent will be the one that is used to create the deck. | ||
* The user is potentially losing the ability to create a deck with the same name as a parent. | ||
* In the real world this does not really matter but adding this note in case that assumption | ||
* In the real world this does not really matter but adding this note in case that assumption | ||
* changes. | ||
*/ | ||
export default function getDeckName( | ||
parent: string | undefined, | ||
name: string | ||
): string { | ||
if (parent && parent !== name) { | ||
return `${parent}::${name}`; | ||
} | ||
return name; | ||
if (parent && parent !== name) { | ||
return `${parent}::${name}`; | ||
} | ||
return name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import sanitizeTags from "./sanitizeTags" | ||
import sanitizeTags from './sanitizeTags'; | ||
|
||
describe("sanitizeTags", () => { | ||
it.each([ | ||
["spaces are handled", ["this tag"], ["this-tag"]], | ||
["tabs are handled", ["\tthis tag"], ["this-tag"]], | ||
["newlines are handled", ["\nthis tag"], ["this-tag"]], | ||
["double spaces are handled", ["\nthis tag"], ["this-tag"]], | ||
])("%s", (_, input, expected) => { | ||
expect(sanitizeTags(input)).toEqual(expected) | ||
}) | ||
}) | ||
describe('sanitizeTags', () => { | ||
it.each([ | ||
['spaces are handled', ['this tag'], ['this-tag']], | ||
['tabs are handled', ['\tthis tag'], ['this-tag']], | ||
['newlines are handled', ['\nthis tag'], ['this-tag']], | ||
['double spaces are handled', ['\nthis tag'], ['this-tag']], | ||
])('%s', (_, input, expected) => { | ||
expect(sanitizeTags(input)).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
const sanitizeTags = ( | ||
tags: string[] | ||
): string[] => tags.map(($1) => $1.trim().replace(/\s+/g, "-")) | ||
const sanitizeTags = (tags: string[]): string[] => | ||
tags.map(($1) => $1.trim().replace(/\s+/g, '-')); | ||
|
||
export default sanitizeTags | ||
export default sanitizeTags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import path from "path"; | ||
import path from 'path'; | ||
|
||
export const TEMPLATE_DIR = path.join(__dirname, "../templates"); | ||
export const TEMPLATE_DIR = path.join(__dirname, '../templates'); | ||
|
||
export const ALLOWED_ORIGINS = [ | ||
"http://localhost:8080", | ||
"http://localhost:2020", | ||
"https://dev.notion2anki.alemayhu.com", | ||
"https://dev.2anki.net", | ||
"https://notion.2anki.com", | ||
"https://2anki.net", | ||
"https://2anki.com", | ||
"https://notion.2anki.net", | ||
"https://dev.notion.2anki.net", | ||
"https://notion.2anki.net/", | ||
"https://staging.2anki.net", | ||
"https://templates.2anki.net/", | ||
'http://localhost:8080', | ||
'http://localhost:2020', | ||
'https://dev.notion2anki.alemayhu.com', | ||
'https://dev.2anki.net', | ||
'https://notion.2anki.com', | ||
'https://2anki.net', | ||
'https://2anki.com', | ||
'https://notion.2anki.net', | ||
'https://dev.notion.2anki.net', | ||
'https://notion.2anki.net/', | ||
'https://staging.2anki.net', | ||
'https://templates.2anki.net/', | ||
]; | ||
|
||
export function resolvePath(dir: string, x: string) { | ||
const p = path | ||
.resolve(path.join(dir, x)) | ||
.replace(/app.asar/g, "app.asar.unpacked"); | ||
return x.endsWith("/") ? p + "/" : p; | ||
.replace(/app.asar/g, 'app.asar.unpacked'); | ||
return x.endsWith('/') ? `${p}/` : p; | ||
} | ||
|
||
export const TIME_21_MINUTES_AS_SECONDS = 1260; | ||
|
||
export const ONE_HOUR = 60 * 60 * 1000; | ||
|
||
export const BUILD_DIR = process.env.WEB_BUILD_DIR || path.join(__dirname, "../../web/build") | ||
export const INDEX_FILE = path.join(BUILD_DIR, "index.html"); | ||
export const BUILD_DIR = | ||
process.env.WEB_BUILD_DIR || path.join(__dirname, '../../web/build'); | ||
export const INDEX_FILE = path.join(BUILD_DIR, 'index.html'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const IsDebug = () => { | ||
return process.env.SPACES_DEFAULT_BUCKET_NAME == "dev.2anki.net"; | ||
}; | ||
export const IsDebug = () => | ||
process.env.SPACES_DEFAULT_BUCKET_NAME == 'dev.2anki.net'; |
Oops, something went wrong.