add prettier to project

This commit is contained in:
Yanick Champoux 2024-02-01 13:49:55 -05:00
parent 0527f3b1fe
commit 44c3f028bd
3 changed files with 71 additions and 65 deletions

View File

@ -1,8 +0,0 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

12
.prettierrc.cjs Normal file
View File

@ -0,0 +1,12 @@
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 80,
tabWidth: 4,
useTabs: false,
plugins: ['prettier-plugin-svelte'],
svelteSortOrder: 'options-markup-scripts-styles',
svelteStrictMode: false,
svelteAllowShorthand: true,
};

View File

@ -18,7 +18,7 @@ export async function fetch_guild_users (guild_id) {
const insert = db.prepare('INSERT OR IGNORE INTO bgg_user (username) VALUES(@username)');
users.forEach( username => insert.run({username}));
users.forEach((username) => insert.run({ username }));
return users;
}
@ -27,7 +27,6 @@ export async function fetch_guild_users (guild_id) {
}
export function extract_user_forsale(page) {
const $ = load(page);
const games = [];
@ -43,7 +42,7 @@ export function extract_user_forsale(page) {
if (find_price) data.price = parseInt(find_price[1]);
games.push(data);
})
});
return games;
}
@ -51,18 +50,19 @@ export function extract_user_forsale(page) {
async function fetch_user_forsale(username, n = 1) {
if (n > 5) throw new Error("couldn't get collection");
const res = await fetch(`https://boardgamegeek.com/xmlapi2/collection?trade=1&username=${username}`);
const res = await fetch(
`https://boardgamegeek.com/xmlapi2/collection?trade=1&username=${username}`
);
if (res.status === 202) {
return new Promise((accept, reject) => {
setTimeout(() => {
fetch_user_forsale(username,n+1).then(accept)
}, 2000)
})
fetch_user_forsale(username, n + 1).then(accept);
}, 2000);
});
}
if( res.status === 200 )
return extract_user_forsale( await res.text() );
if (res.status === 200) return extract_user_forsale(await res.text());
throw new Error("couldn't get the collection for " + username);
}
@ -72,7 +72,9 @@ async function update_user_games(username) {
// TODO only change the games that changed
// TODO only change users that got added or removed
const insert = db.prepare( 'INSERT into game (username, bgg_id, name, thumbnail, notes,price) VALUES(@username,@bgg_id,@name,@thumbnail,@notes,@price)' );
const insert = db.prepare(
'INSERT into game (username, bgg_id, name, thumbnail, notes,price) VALUES(@username,@bgg_id,@name,@thumbnail,@notes,@price)'
);
await db.prepare('DELETE FROM game where username = @username').run({ username });
@ -83,10 +85,10 @@ async function update_user_games(username) {
...game
});
}
}
await update_user_games('yenzie').then( () => console.log('is done')).catch( e => console.error(e));
await update_user_games('yenzie')
.then(() => console.log('is done'))
.catch((e) => console.error(e));
/*
const usernames = await fetch_guild_users('1610');