Skip to content

Instantly share code, notes, and snippets.

@NerOcrO
Last active May 17, 2024 12:11
Show Gist options
  • Save NerOcrO/39b173ccaea42d13fedcbc7cb18240fc to your computer and use it in GitHub Desktop.
Save NerOcrO/39b173ccaea42d13fedcbc7cb18240fc to your computer and use it in GitHub Desktop.
eslint linter prettier
// Prettier est inutile sur un projet où il y a eslint
{
"printWidth": 120, // max-len
"tabWidth": 2, // indent
"useTabs": false, // no-tabs
"semi": false, // semi
"singleQuote": true, // quotes
"quoteProps": "as-needed", // quote-props
"jsxSingleQuote": false, // jsx-quotes
"trailingComma": "es5", // comma-dangle
"bracketSpacing": true, // array-bracket-spacing et object-curly-spacing
"bracketSameLine": false, // react/jsx-closing-bracket-location
"arrowParens": "always", // arrow-parens
"parser": "typescript",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "never",
"htmlWhitespaceSensitivity": "strict", // osef
"endOfLine": "lf", // eol-last
"embeddedLanguageFormatting": "auto"
}
#!/bin/bash
expressions_a_ne_pas_ecrire=(
# Prod
"type (.*) = {" # Ajouter Readonly
"useState\(" # Ajouter un générique
"React\." # Importer la méthode de React
"@ts-ignore" # Demander de l'aide aux autres
"eslint-disable" # Demander de l'aide aux autres
# Style
"font-size" # Utiliser la variable CSS dans reboot.css
"font-weight" # Utiliser la variable CSS dans reboot.css
"font-style" # Utiliser la variable CSS dans reboot.css
"#[a-f0-9]{3,6}" # Utiliser la variable de couleur dans StyleThemeGenerator
"[0-9]{1,3}rem" # Utiliser la fonction pixelsToRem dans StyleThemeGenerator
"[0-9]{1,3}px" # Utiliser la fonction pixelsToRem dans StyleThemeGenerator
# Test
"jest.mock\(" # Utiliser jest.spyOn
"mockResolvedValue\(" # Utiliser mockResolvedValueOnce
"mockRejectedValue\(" # Utiliser mockRejectedValueOnce
"jest\.clearAllMocks\(" # Ne pas utiliser, c'est déjà configurer
"jest\.resetAllMocks\(" # Ne pas utiliser, c'est déjà configurer
"jest\.restoreAllMocks\(" # Ne pas utiliser, c'est déjà configurer
"act\(" # Utiliser waitFor
)
# Permet de boucler sur le retour chariot plutôt que l'espace.
IFS=$'\n'
compteur=0
souligne=`tput smul`
rouge="\e[0;91m"
vert="\e[0;92m"
couleur_info="\e[0;96m"
couleur_reset="\e[0m"
saut_de_ligne="\n"
lister_les_fichiers_ajoutés_a_git() {
git diff --name-only --cached | grep -E "\.t(s|sx)$"
# find . -regextype posix-extended -regex "(.*)\.t(s|sx)" \
# -not -path "./node_modules/*" \
# -not -name "recupererChangelogUseCase.ts" \
# -not -name "EmailNotificationNouvellesCandidatures.ts" \
# -not -name "envoyerNotificationNouvellesCandidatures.useCase.test.ts"
}
for fichier in $(lister_les_fichiers_ajoutés_a_git); do
chemin_du_fichier="${souligne}${fichier}${couleur_reset}"
erreurs_a_afficher=''
for expression in ${expressions_a_ne_pas_ecrire[@]}; do
lignes=$(grep -nEI "$expression" $fichier)
# Concatène les lignes d'erreur pour les afficher plus tard.
for ligne in ${lignes}; do
numero_de_ligne=$(cut -d: -f1 <<< $ligne)
erreur=$(cut -d: -f2,3,4 <<< $ligne | xargs)
erreurs_a_afficher+=" ${vert}l:${numero_de_ligne}\t${rouge}${erreur}${couleur_reset}\n"
compteur=$((compteur + 1))
done
done
if [ ! -z $erreurs_a_afficher ]; then
echo -e $chemin_du_fichier$saut_de_ligne$erreurs_a_afficher
fi
done
if [ $compteur -gt 0 ]; then
echo -e "$compteur erreurs"
echo -e "${couleur_info}If you want to bypass it, add --no-verify or -n option when committing.${couleur_reset}${saut_de_ligne}"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment