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

Feature/linters v2 #90

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
125 changes: 94 additions & 31 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@

const fs = require('fs');
const path = require('path');


const prettierOptions = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '.prettierrc'), 'utf8'),
);

// const app = JSON.parse(path.resolve(__dirname, 'app'));

module.exports = {
root: true,
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/react'],
plugins: ['prettier', 'redux-saga', 'react-native', 'react', 'react-hooks', 'jsx-a11y'],
extends: [
'airbnb',
'prettier',
'prettier/react',
'plugin:prettier/recommended',
'plugin:sonarjs/recommended',
'plugin:security/recommended-legacy',
'plugin:fp/recommended'
],
plugins: [
'github',
'immutable',
'sonarjs',
'prettier',
'redux-saga',
'react-native',
'react',
'react-hooks',
'jsx-a11y',
'fp'
],
env: {
jest: true,
browser: true,
node: true,
es6: true,
es6: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
jsx: true
}
},
rules: {
'prettier/prettier': ['error', prettierOptions],
Expand Down Expand Up @@ -53,8 +69,8 @@ module.exports = {
// NOTE: If this error triggers, either disable it or add
// your custom components, labels and attributes via these options
// See https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-associated-control.md
controlComponents: ['Input'],
},
controlComponents: ['Input']
}
],
'jsx-a11y/label-has-for': 0,
'jsx-a11y/mouse-events-have-key-events': 2,
Expand Down Expand Up @@ -82,29 +98,76 @@ module.exports = {
'redux-saga/no-yield-in-race': 2,
'redux-saga/yield-effects': 2,
'require-yield': 0,
'react/no-array-index-key': 0
'react/no-array-index-key': 0,
'react/jsx-curly-newline': 0,
'react/jsx-one-expression-per-line': 0,
'react/jsx-wrap-multilines': 0,
'react/no-unused-prop-types': 0,
'max-lines-per-function': ['error', 250],
'no-else-return': 'error',
'max-params': ['error', 3],
'require-jsdoc': [
'error',
{
require: {
FunctionDeclaration: true,
MethodDefinition: false,
ClassDeclaration: false,
ArrowFunctionExpression: false,
FunctionExpression: false
}
}
],
'no-shadow': 'error',
complexity: ['error', 10],
'no-empty': 'error',
'import/order': [
'error',
{
groups: [
['builtin', 'external', 'internal', 'parent', 'sibling', 'index']
]
}
],
'immutable/no-let': 2,
'immutable/no-this': 2,
'max-lines': ['error', 350],
'react-native/no-unused-styles': 2,
'react-native/split-platform-components': 2,
'react-native/no-inline-styles': 2,
'react-native/no-color-literals': 2,
'react-native/no-raw-text': 2,
'react-native/no-single-element-style-arrays': 2,
'fp/no-mutation': [
'error',
{
exceptions: [{ property: 'propTypes' }, { property: 'defaultProps' }]
}
],
'fp/no-nil': 0,
'fp/no-unused-expression': 0
},
"settings": {
"import/resolver": {
"node": {
"app": "./app",
"context": "app",
"resolve": {
"alias": {
"@assets": "./app/assets",
"@components": "./app/components",
"@containers": "./app/containers",
"@config": "./app/config",
"@navigators": "./app/navigators",
"@services": "./app/services",
"@themes": "./app/themes",
"@utils": "./app/utils"
settings: {
'import/resolver': {
node: {
app: './app',
context: 'app',
resolve: {
alias: {
'@assets': './app/assets',
'@components': './app/components',
'@containers': './app/containers',
'@config': './app/config',
'@navigators': './app/navigators',
'@services': './app/services',
'@themes': './app/themes',
'@utils': './app/utils'
},
"paths": ["app"],
"modules": ["app", 'node_modules'],
"extensions": ['.js', '.jsx', '.json', '.coffee', '.cjsx'],
paths: ['app'],
modules: ['app', 'node_modules'],
extensions: ['.js', '.jsx', '.json', '.coffee', '.cjsx']
}
}
}
}
}
};
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 15 additions & 12 deletions app/components/atoms/If/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
*
*/
// eslint-disable-next-line
import React from 'react'
import React from 'react';
import Proptypes from 'prop-types';
const If = props => (props.condition ? props.children : props.otherwise);
If.propsTypes = {
condition: Proptypes.bool,
otherwise: Proptypes.oneOfType([
Proptypes.arrayOf(Proptypes.node),
Proptypes.node
]),
children: Proptypes.oneOfType([
Proptypes.arrayOf(Proptypes.node),
Proptypes.node
])
};
// eslint-disable-next-line fp/no-mutating-assign
Object.assign(If, {
propsTypes: {
condition: Proptypes.bool,
otherwise: Proptypes.oneOfType([
Proptypes.arrayOf(Proptypes.node),
Proptypes.node
]),
children: Proptypes.oneOfType([
Proptypes.arrayOf(Proptypes.node),
Proptypes.node
])
}
});
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
If.defaultProps = {
otherwise: null
};
Expand Down
1 change: 1 addition & 0 deletions app/components/atoms/LanguageProvider/reducer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-small-switch */
/*
*
* LanguageProvider reducer
Expand Down
11 changes: 11 additions & 0 deletions app/components/molecules/CharacterWithQuote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ const CharacterImage = styled.Image`
margin: 0 auto;
`;

/**
* Renders a component displaying a character with associated quote and image.
*
* @component
* @param {Object} props - The props object.
* @param {Object} props.user - The user object containing character and quote information.
* @param {string} props.user.character - The character name to display.
* @param {string} props.user.image - The URL of the image associated with the character.
* @param {string} props.user.quote - The quote associated with the character.
* @returns {JSX.Element} A React element representing the character display with quote.
*/
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
function CharacterWithQuote({ user }) {
return (
<>
Expand Down
1 change: 1 addition & 0 deletions app/i18n.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable fp/no-mutating-assign */
/**
* i18n.js
*
Expand Down
1 change: 1 addition & 0 deletions app/scenes/RootScreen/reducer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-small-switch */
import { createActions } from 'reduxsauce';
import { fromJS } from 'immutable';
import produce from 'immer';
Expand Down
9 changes: 8 additions & 1 deletion app/scenes/RootScreen/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { rootScreenTypes } from './reducer';
export function* startup() {
setTimeout(() => navigateAndReset('MainScreen'), 1000);
}

/**
* Generator function for the startup saga.
* Watches for the latest occurrence of the specified action type and triggers the startup process.
*
* @generator
* @function startUpSaga
* @yields {Effect} Effect object representing the takeLatest behavior
*/
export default function* startUpSaga() {
yield takeLatest(rootScreenTypes.STARTUP, startup);
}
1 change: 1 addition & 0 deletions app/services/navigationService.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable fp/no-mutating-assign */
import { NavigationActions, StackActions } from '@react-navigation/compat';
/**
* The navigation is implemented as a service so that it can be used outside of components, for example in sagas.
Expand Down
2 changes: 2 additions & 0 deletions app/utils/apiUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable sonarjs/no-small-switch */
/* eslint-disable fp/no-mutating-assign */
import { create } from 'apisauce';
import mapKeysDeep from 'map-keys-deep';
import camelCase from 'lodash/camelCase';
Expand Down
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @param {Function} api.cache - Function used for caching Babel configuration.
* @returns {object} Babel configuration object with presets and plugins.
*/
module.exports = function(api = { cache: () => {} }) {
// eslint-disable-next-line fp/no-mutation
module.exports = (api = { cache: () => {} }) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The review comment suggested verifying the consistency of using arrow functions in configuration files across the project. The script executed searched for the pattern module.exports = ( in JavaScript files, which would typically indicate the use of arrow functions. The results show that the only instance of an arrow function in a module export is found in babel.config.js.

This indicates that the use of arrow functions in configuration files is not a common practice throughout the project. Therefore, the original review comment's concern about consistency is valid.

Conclusion: The use of an arrow function in babel.config.js is not consistent with other configuration files in the project.

Analysis chain

The use of an arrow function for defining the Babel configuration is a modern syntax choice. Ensure that this change is consistent with the coding standards of the project, especially regarding the use of arrow functions in configuration files.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for consistency in the use of arrow functions in other configuration files
rg "module.exports = \(" --type js

Length of output: 102

api.cache(true);
return {
presets: ['babel-preset-expo'],
Expand Down
1 change: 1 addition & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

// eslint-disable-next-line fp/no-mutation
module.exports = getDefaultConfig(__dirname);
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"axios-mock-adapter": "^1.17.0",
"babel-plugin-react-intl": "3.0.1",
"babel-preset-react-native": "^4.0.1",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-github": "^4.10.2",
"eslint-plugin-immutable": "^1.0.0",
"eslint-plugin-security": "^3.0.0",
"eslint-plugin-sonarjs": "^0.25.1",
"expo": "~47.0.14",
"expo-image-picker": "~14.0.1",
"expo-splash-screen": "~0.17.5",
Expand Down
Loading