Skip to content

Nettoyage du code #689

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
990e129
feat(action): test build actions
Gabriel29306 Dec 13, 2024
5194655
fix(action): build version
Gabriel29306 Dec 13, 2024
688de03
fix(action): build using expo prebuild
Gabriel29306 Dec 13, 2024
19a10cd
fix(action): indent
Gabriel29306 Dec 13, 2024
4b288c5
fix(action): indent
Gabriel29306 Dec 13, 2024
41bf273
fix(action): use java 17
Gabriel29306 Dec 13, 2024
1a1bae8
fix(action): Increment Version Based on Release
Gabriel29306 Dec 13, 2024
567d42e
fix(action): resolve publish errors
Gabriel29306 Dec 13, 2024
451dca0
fix(action): tests
Gabriel29306 Dec 13, 2024
e1f7614
fix(action): test
Gabriel29306 Dec 14, 2024
b458b96
fix(action): test
Gabriel29306 Dec 14, 2024
b1f3d27
fix(actions): test
Gabriel29306 Dec 14, 2024
fa2e4f8
fix(action): Is ot going to work this time ?
Gabriel29306 Dec 14, 2024
6008824
fix(action): Why isn't working !
Gabriel29306 Dec 14, 2024
2b24232
fix(action): tag name
Gabriel29306 Dec 14, 2024
8ef1594
chore(action): remove debug
Gabriel29306 Dec 14, 2024
6a6766b
fix(action)
Gabriel29306 Dec 14, 2024
824ab0a
fix(action)
Gabriel29306 Dec 14, 2024
8ed4ad7
debug
Gabriel29306 Dec 14, 2024
ada785b
debug
Gabriel29306 Dec 14, 2024
e3e6f0d
fix(action): include pre versions in get latest version
Gabriel29306 Dec 14, 2024
b0f827a
Merge branch 'PapillonApp:main' into main
Gabriel29306 Dec 20, 2024
8999f7e
Merge branch 'PapillonApp:main' into main
Gabriel29306 Dec 24, 2024
d85268e
fix(build): let gradle choose the good sdk
Gabriel29306 Dec 24, 2024
551f089
fix: Rename service_alise.png to service_alise.jpg
Gabriel29306 Dec 24, 2024
1d51262
fix(action): Rename service_alise.png to service_alise.jpg
Gabriel29306 Dec 24, 2024
806d4cf
fix(action): update service_alise.png into service_alise.jpg in all f…
Gabriel29306 Dec 24, 2024
7d796c2
chore(action): remove unnecessary step
Gabriel29306 Dec 27, 2024
37bc830
Merge branch 'PapillonApp:main' into main
Gabriel29306 Dec 27, 2024
835c2c0
feat(action/build): add emojis to steps
Gabriel29306 Dec 27, 2024
7b428b5
Merge branch 'PapillonApp:main' into main
Gabriel29306 Dec 29, 2024
9a5b080
Merge branch 'PapillonApp:main' into main
Gabriel29306 Jan 4, 2025
792dc97
feat(action/build): Change weekly build time for 00h00 UTC
Gabriel29306 Jan 5, 2025
fe78a9a
fix(action): update pawnote to permit Papillon to work in new Pronote…
Gabriel29306 Jan 8, 2025
c4c594a
Merge branch 'PapillonApp:main' into main
Gabriel29306 Jan 8, 2025
704c81d
chore(action): remove unused step
Gabriel29306 Jan 8, 2025
4340bad
Merge branch 'PapillonApp:main' into main
Gabriel29306 Jan 10, 2025
544f1e2
lint: don't use `var`
Gabriel29306 Jan 24, 2025
84f98b4
lint: inaccesible code
Gabriel29306 Jan 24, 2025
31bd5de
lint: simplify conditions
Gabriel29306 Jan 24, 2025
888f024
lint: remove unecessary keywords `void`, `return`, `await`
Gabriel29306 Jan 24, 2025
4de5164
perf: add missing `break`
Gabriel29306 Jan 24, 2025
f5fc04d
lint: unecessary instruction
Gabriel29306 Jan 24, 2025
ac5569c
lint: simplify ratio (`1/1`=>`1`)
Gabriel29306 Jan 24, 2025
5ba5eb0
lint: `useEffect` need to be called in every render.
Gabriel29306 Jan 24, 2025
52f4498
feat(lint): unused vars
Gabriel29306 Jan 25, 2025
f6166de
feat(tsconfig): add `jsx` option
Gabriel29306 Jan 25, 2025
7a50028
fix: lint
Gabriel29306 Jan 25, 2025
4914397
fix(lint): ignore func args for unused var
Gabriel29306 Jan 25, 2025
e4e777c
lint: remove unused variables
Gabriel29306 Jan 25, 2025
b0e65a4
feat(lint): discouraging the use of var and encouraging the use of co…
Gabriel29306 Jan 25, 2025
b6cca91
lint: duplicated imports
Gabriel29306 Jan 25, 2025
c5f0d33
lint: no-unneeded-ternary
Gabriel29306 Jan 25, 2025
0da5aec
lint: remove extra semicolons
Gabriel29306 Jan 25, 2025
c4e0832
lint: no-irregular-whitespace
Gabriel29306 Jan 25, 2025
5a4bb41
lint: no-mixed-spaces-and-tabs
Gabriel29306 Jan 25, 2025
8ca9ff2
lint: no-empty
Gabriel29306 Jan 25, 2025
be68e53
lint: no-useless-escape
Gabriel29306 Jan 25, 2025
047ed6a
Merge branch 'PapillonApp:main' into main
Gabriel29306 Jan 25, 2025
93a6f2f
feat(lint): add custom rules
Gabriel29306 Jan 25, 2025
8c3f1ee
lint: simplify ternary
Gabriel29306 Jan 25, 2025
4b93ba4
Merge remote-tracking branch 'origin' into clean-the-code-as-fuck-is-…
Gabriel29306 Jan 25, 2025
11e139a
lint
Gabriel29306 Jan 25, 2025
e33ea6f
Merge branch 'PapillonApp:main' into main
Gabriel29306 Jan 25, 2025
337ff94
feat(build): add patchs
Gabriel29306 Jan 26, 2025
3ea338c
Update build.yml
Gabriel29306 Jan 27, 2025
0bb93c9
Update build.yml
Gabriel29306 Jan 28, 2025
61d9a72
Merge remote-tracking branch 'origin/main' into clean-the-code-as-fuc…
Feb 15, 2025
d5735fb
chore: remove unusable file
Gabriel29306 Feb 15, 2025
6d3bb38
Merge remote-tracking branch 'origin/main' into clean-the-code-as-fuc…
Gabriel29306 Mar 10, 2025
ca238c3
chore(lint): semicolon and eol-last
Gabriel29306 Mar 14, 2025
8629588
chore(lint): imports
Gabriel29306 Mar 14, 2025
7b50c97
chore(lint): readability
Gabriel29306 Mar 14, 2025
f116ac3
chore(lint): typing
Gabriel29306 Mar 14, 2025
6c28603
chore(lint): unused
Gabriel29306 Mar 14, 2025
fb58299
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Mar 14, 2025
1a01791
feat(logs): use custom logger instead of console builtin and enhance …
Gabriel29306 Mar 15, 2025
b29e3e2
fix: package-lock.json
Gabriel29306 Mar 15, 2025
a7eb333
fix: package-lock.json
Gabriel29306 Mar 15, 2025
7eb513b
fix(lint): remove unused comma
Gabriel29306 Mar 17, 2025
c186e80
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Mar 17, 2025
7cd3f17
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Mar 19, 2025
01c933d
chore(lint)
Gabriel29306 Mar 19, 2025
2f3dc20
fix(vscode): oups
Gabriel29306 Mar 19, 2025
8742457
chore(lint)
Gabriel29306 Mar 20, 2025
9a14363
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Mar 20, 2025
55d3f9b
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Mar 21, 2025
9791c20
feat(lint): arrow-spacing
Gabriel29306 Mar 21, 2025
1b12f21
chore: use `TouchableOpacity` from react-native instead of react-nati…
Gabriel29306 Mar 22, 2025
65600e1
chore: remove unused file
Gabriel29306 Mar 22, 2025
8b4b698
feat(lint): remove unused func args
Gabriel29306 Mar 22, 2025
0e621c9
fi(lint): unued assertion
Gabriel29306 Mar 22, 2025
ada94dd
feat(restaurant): use hook instead of static to use actualised version
Gabriel29306 Mar 22, 2025
ff1ff70
feat(esthetic): split the two useState var into pair
Gabriel29306 Mar 22, 2025
a8ff2b2
feat(lint): simplify ternary
Gabriel29306 Mar 22, 2025
6eca183
feat(lint): esthetic
Gabriel29306 Mar 23, 2025
dbcf632
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Mar 23, 2025
88792cf
Merge remote-tracking branch 'origin/main' into clean-the-code-as-fuc…
Gabriel29306 Apr 3, 2025
68cb4a0
lint
Gabriel29306 Apr 3, 2025
2cf145b
Merge branch 'main' into clean-the-code-as-fuck-is-possible
Gabriel29306 Apr 7, 2025
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"lint"
],
"typescript.tsdk": "node_modules/typescript/lib"
}
}
11 changes: 6 additions & 5 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { AccountService } from "@/stores/account/types";
import { log } from "@/utils/logger/logger";
import { isExpoGo } from "@/utils/native/expoGoAlert";
import { atobPolyfill, btoaPolyfill } from "js-base64";
// eslint-disable-next-line no-duplicate-imports
import { registerBackgroundTasks } from "@/background/BackgroundTasks";
import { SoundHapticsProvider } from "@/hooks/Theme_Sound_Haptics";
import { PapillonNavigation } from "@/router/refs";
import * as Device from "expo-device";
import * as ScreenOrientation from "expo-screen-orientation";
import {getToLoadFonts} from "@/consts/Fonts";
import { getToLoadFonts } from "@/consts/Fonts";
import { useFlagsStore } from "@/stores/flags";

SplashScreen.preventAutoHideAsync();
Expand All @@ -32,9 +33,9 @@ export default function App () {
const [appState, setAppState] = useState(AppState.currentState);
const currentAccount = useCurrentAccount((store) => store.account);
const switchTo = useCurrentAccount((store) => store.switchTo);
const accounts = useAccounts((store) => store.accounts).filter(account => !account.isExternal);
const accounts = useAccounts((store) => store.accounts).filter((account) => !account.isExternal);

const defined = useFlagsStore(state => state.defined);
const defined = useFlagsStore((state) => state.defined);
const [fontsLoaded] = useFonts(getToLoadFonts(defined));

useEffect(() => {
Expand Down Expand Up @@ -107,7 +108,7 @@ export default function App () {
break;
}
}
await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 1000));
}
await AsyncStorage.removeItem("@background_timestamp");
}, [currentAccount, switchTo, getBackgroundTimeLimit]);
Expand Down Expand Up @@ -166,4 +167,4 @@ export default function App () {
<Router />
</SoundHapticsProvider>
);
}
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module.exports = function (api) {
"react-native-reanimated/plugin"
],
};
};
};
30 changes: 28 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const stylistic = require("@stylistic/eslint-plugin");
const unusedImports = require("eslint-plugin-unused-imports");
const typescript = require("@typescript-eslint/parser");

const custom_rules = require("./eslint_rules/plugin.js");

module.exports = [
{ // Ignored directory
ignores: [
Expand Down Expand Up @@ -29,15 +31,39 @@ module.exports = [
},
plugins: {
"@stylistic": stylistic,
"unused-imports": unusedImports
"unused-imports": unusedImports,
"custom": custom_rules
},
rules: {
"@stylistic/indent": ["error", 2],
"@stylistic/no-trailing-spaces": "error",
"@stylistic/quotes": ["error", "double"],
"@stylistic/semi": ["error", "always"],
"@stylistic/eol-last": ["error", "always"],
"@stylistic/space-before-function-paren": ["error", "always"],
"unused-imports/no-unused-imports": "error"
"@stylistic/no-extra-semi": "error",
"@stylistic/no-mixed-spaces-and-tabs": "error",
"@stylistic/object-curly-spacing": ["error", "always"],
"@stylistic/keyword-spacing": ["error", {
"before": true
}],
"@stylistic/arrow-parens": "error",
"@stylistic/arrow-spacing": "error",
"unused-imports/no-unused-imports": "error",
"no-unused-vars": ["error", {
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}],
"no-var": "error",
"no-irregular-whitespace": "error",
"no-unneeded-ternary": "error",
"no-duplicate-imports": "error",
"no-empty": "error",
"no-useless-escape": "error",
"custom/redundant-logical": "error",
"custom/no-redundant-ternary": "error"
}
}
];
78 changes: 78 additions & 0 deletions eslint_rules/no-redundant-ternary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Detect and transform nested ternary operators into nullish coalescing chains",
category: "Best Practices",
recommended: false
},
schema: [],
messages: {
redundantNestedTernary: "The nested ternary can be simplified using nullish coalescing operators"
},
fixable: "code",
},
create (context) {
function processConditionalExpression (node) {
const sourceCode = context.getSourceCode();

// Fonction récursive pour construire la chaîne de nullish coalescing
function buildNullishChain (node) {
if (node.type !== "ConditionalExpression") {
return sourceCode.getText(node);
}

const test = sourceCode.getText(node.test);

// Si c'est un ternaire imbriqué dans l'alternate
if (node.alternate.type === "ConditionalExpression") {
// Récupérer l'expression complète du consequent
const nextValueNode = node.alternate.consequent;

// Si c'est un accès à une propriété imbriquée, ajouter l'optional chaining
if (nextValueNode.type === "MemberExpression") {
const object = sourceCode.getText(nextValueNode.object);
const property = sourceCode.getText(nextValueNode.property);
return `${test} ?? ${object}?.${property} ?? ${sourceCode.getText(node.alternate.alternate)}`;
}

const nextValue = sourceCode.getText(nextValueNode);
return `${test} ?? ${nextValue} ?? ${sourceCode.getText(node.alternate.alternate)}`;
}

return `${test} ?? ${sourceCode.getText(node.alternate)}`;
}

// Vérifie si c'est un cas valide à transformer
function isValidTransform (node) {
if (!node || node.type !== "ConditionalExpression") return false;

const test = sourceCode.getText(node.test);
const consequent = sourceCode.getText(node.consequent);

// Soit test et consequent sont identiques
if (test === consequent) return true;

// Soit c'est dans un alternate d'un ternaire valide
return !!(node.parent?.type === "ConditionalExpression"
&& node.parent.alternate === node
&& isValidTransform(node.parent));
}

// Vérifie si c'est un cas de ternaire imbriqué à transformer
if (isValidTransform(node)) {
context.report({
node,
messageId: "redundantNestedTernary",
fix (fixer) {
return fixer.replaceText(node, buildNullishChain(node));
}
});
}
}

return {
ConditionalExpression: processConditionalExpression
};
}
};
10 changes: 10 additions & 0 deletions eslint_rules/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const redundant_logical = require("./redundant-logical.js");
const no_redundant_ternary = require("./no-redundant-ternary.js");

const plugin = {
rules: {
"redundant-logical": redundant_logical,
"no-redundant-ternary": no_redundant_ternary
}
};
module.exports = plugin;
63 changes: 63 additions & 0 deletions eslint_rules/redundant-logical.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const ts = require("typescript");

module.exports = {
meta: {
type: "problem",
docs: {
description: "Detect redundant `x || x.y` or `x && x` patterns",
category: "Best Practices",
recommended: false
},
schema: [],
messages: {
redundantLogical: "The logical expression `{{ expression }}` is redundant. Consider simplifying it."
}
},
create (context) {
const parserServices = context.parserServices;
if (!parserServices?.program) {
return {}; // Ignorer si TypeScript n'est pas activé
}
const typeChecker = parserServices.program.getTypeChecker();

return {
LogicalExpression (node) {
if (node.operator === "&&" || node.operator === "||") {
const left = context.getSourceCode().getText(node.left);
const right = context.getSourceCode().getText(node.right);

if (right.startsWith(left)) {
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.left);
const type = typeChecker.getTypeAtLocation(tsNode);
const isNullable = (type.getFlags() & ts.TypeFlags.Null) !== 0;

if ((node.operator === "&&" && isNullable) ||
(node.operator === "||" && !isNullable)) {
return;
}

// Extraire la partie après le point (ex: pour "x.y", on récupère "y")
const suffix = right.slice(left.length);

context.report({
node,
messageId: "redundantLogical",
data: {
expression: `${left} ${node.operator} ${right}`
},
fix (fixer) {
if (node.operator === "&&") {
// Pour &&, utiliser l'opérateur optionnel
return fixer.replaceText(node, `${left}?${suffix}`);
} else {
// Pour ||, utiliser l'accès direct
return fixer.replaceText(node, `${right}`);
}
}
});
}
}
}
};
}
};
4 changes: 2 additions & 2 deletions plugins/notifee-mod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { withProjectBuildGradle } = require("expo/config-plugins");

module.exports = function withNotifeeRepo (config) {
return withProjectBuildGradle(config, async config => {
return withProjectBuildGradle(config, async (config) => {
const contents = config.modResults.contents;

if (!contents.includes("@notifee/react-native")) {
Expand All @@ -14,4 +14,4 @@ module.exports = function withNotifeeRepo (config) {

return config;
});
};
};
6 changes: 3 additions & 3 deletions src/addons/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async function get_addons_list (): Promise<AddonManifest[]> {
continue;
}

manifest.placement.forEach(placement => {
manifest.placement.forEach((placement) => {
placement.main = FileSystem.documentDirectory + "addons/" + addon + "/" + placement.main;
});

Expand Down Expand Up @@ -207,9 +207,9 @@ async function get_home_widgets (): Promise<AddonManifest[]> {

async function get_settings_widgets (): Promise<AddonPlacementManifest[]> {
let addons = await get_addons_list();
var res: Array<AddonPlacementManifest> = [];
let res: Array<AddonPlacementManifest> = [];
addons.forEach((addon) => {
for (var i = 0; i < addon.placement.length; i++) {
for (let i = 0; i < addon.placement.length; i++) {
if (addon.placement[i].placement == "PLACE_SETTINGS_PAGE")
res.push({
index: i,
Expand Down
24 changes: 14 additions & 10 deletions src/background/BackgroundTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,37 @@ const notifeeEvent = async () => {

// Gestion des badges quand app en arrière-plan
notifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;
const { pressAction } = detail;

switch (type) {
case EventType.ACTION_PRESS:
console.log(`[Notifee] Action press: ${pressAction?.id}`);

case EventType.DISMISSED:
case EventType.ACTION_PRESS: {
log(`[Notifee] Action press: ${pressAction?.id}`, "NOTIFEE/BK");
break;
}
case EventType.DISMISSED: {
let badgeCount = await notifee.getBadgeCount();
badgeCount--;
await notifee.setBadgeCount(badgeCount);
break;
}
}
});

// Gestion des badges quand app en premier plan
notifee.onForegroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;
const { pressAction } = detail;

switch (type) {
case EventType.ACTION_PRESS:
console.log(`[Notifee] Action press: ${pressAction?.id}`);

case EventType.DISMISSED:
case EventType.ACTION_PRESS: {
log(`[Notifee] Action press: ${pressAction?.id}`, "NOTIFEE/FW");
break;
}
case EventType.DISMISSED: {
let badgeCount = await notifee.getBadgeCount();
badgeCount--;
await notifee.setBadgeCount(badgeCount);
break;
}
}
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/background/Notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const papillonNotify = async (
channelId,
timestamp,
badgeCount,
showTimestamp: channelId !== "Status" ? true : false,
showChronometer: channelId === "Status" ? true : false,
showTimestamp: channelId !== "Status",
showChronometer: channelId === "Status",
smallIcon: "@mipmap/ic_launcher_foreground",
color: AndroidColor.GREEN,
pressAction: {
Expand Down
1 change: 0 additions & 1 deletion src/background/data/Homeworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const fetchHomeworks = async (): Promise<Homework[]> => {
if (!firstDate) {
firstDate = new Date(Date.UTC(new Date().getFullYear(), 8, 1));
}
const firstDateEpoch = dateToEpochWeekNumber(firstDate);

const SemaineAct = dateToEpochWeekNumber(new Date());
const currentHwSemaineActuelle = getHomeworks()[SemaineAct] ?? [];
Expand Down
Loading