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 #68

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7c1bc4d
Added Linters and code changes V1
himanshu-wedensday Mar 27, 2024
3f7d9a9
Code Refactor V2
himanshu-wedensday Mar 28, 2024
cf09331
Added linters
himanshu-wedensday Apr 4, 2024
9d49a6e
Refunining Task
himanshu-wedensday Apr 4, 2024
e691b57
import lodash as es6
himanshu-wedensday Apr 4, 2024
456b8b3
cleaned jsdoc
himanshu-wedensday Apr 6, 2024
42ff330
prettier lint
himanshu-wedensday Apr 6, 2024
0f32c8c
resolved coderabbit comment
himanshu-wedensday Apr 6, 2024
ff6929c
wisely used lodash
himanshu-wedensday Apr 8, 2024
adef2e1
Error Message fix
himanshu-wedensday Apr 8, 2024
8c8c98b
adding linting in dev dependences
himanshu-wedensday Apr 8, 2024
610e085
Resolved code rabbit comments
himanshu-wedensday Apr 8, 2024
2229737
Code refactoring
himanshu-wedensday Apr 8, 2024
6dba9cf
reduced loadash size
himanshu-wedensday Apr 9, 2024
aafd61d
test for action.js
himanshu-wedensday Apr 8, 2024
1340a13
test for action.js
himanshu-wedensday Apr 8, 2024
e4677c6
test for setting top level navogator in root component
himanshu-wedensday Apr 8, 2024
1f90a44
test for action.js
himanshu-wedensday Apr 8, 2024
c62a339
removed unused code
himanshu-wedensday Apr 9, 2024
8e5b9b7
Added test for notification service
himanshu-wedensday Apr 8, 2024
9c9a247
navigate function tests
himanshu-wedensday Apr 8, 2024
848e3ff
neater services tests
himanshu-wedensday Apr 8, 2024
40f1415
neater navigation test
himanshu-wedensday Apr 9, 2024
4d5476e
feat: interim
himanshu-wedensday Apr 9, 2024
1f1cc25
neater tests
himanshu-wedensday Apr 9, 2024
af25d94
Merge pull request #73 from wednesday-solutions/feat/notification_ser…
himanshu-wedensday Apr 11, 2024
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
131 changes: 91 additions & 40 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@

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

const prettierOptions = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '.prettierrc'), 'utf8'),
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
);

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

module.exports = {
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
root: true,
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/react'],
plugins: ['prettier', 'redux-saga', 'react-native', 'react', 'react-hooks', 'jsx-a11y'],
extends: [
'airbnb',
'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: {
Copy link

Choose a reason for hiding this comment

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

Remove duplicate prettier plugin entry to clean up the configuration.

  plugins: [
    'github',
    'immutable',
    'sonarjs',
-   'prettier',
    'redux-saga',
    'react-native',
    'react',
    'react-hooks',
    'jsx-a11y',
    'fp'
  ],

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
plugins: [
'github',
'immutable',
'sonarjs',
'prettier',
'redux-saga',
'react-native',
'react',
'react-hooks',
'jsx-a11y',
'fp'
],
plugins: [
'github',
'immutable',
'sonarjs',
'redux-saga',
'react-native',
'react',
'react-hooks',
'jsx-a11y',
'fp'
],

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],
'arrow-body-style': [2, 'as-needed'],
'class-methods-use-this': 0,
'import/imports-first': 0,
Expand All @@ -38,13 +49,6 @@ module.exports = {
'import/no-unresolved': 0,
'import/prefer-default-export': 0,
'react/jsx-props-no-spreading': 0,
indent: [
2,
2,
{
SwitchCase: 1,
},
],
'jsx-a11y/aria-props': 2,
'jsx-a11y/heading-has-content': 0,
'jsx-a11y/label-has-associated-control': [
Expand All @@ -53,8 +57,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 +86,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', 2],
'no-empty': 'error',
Copy link

Choose a reason for hiding this comment

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

The complexity rule is set with a threshold of 2, which is quite low and might be overly restrictive for most functions. Consider increasing this value to allow for more complex but manageable functions.

-    complexity: ['error', 2],
+    complexity: ['error', 10],

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
complexity: ['error', 2],
complexity: ['error', 10],

'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']
}
Comment on lines +149 to +167
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

Based on the script's output, it's evident that most of the directories mentioned in the alias settings of the .eslintrc.js file exist within the project's structure, with the exception of app/containers and the node_modules directory. The absence of app/containers suggests that either the project no longer uses this directory, or it was mistakenly included in the alias settings. The missing node_modules directory could indicate that dependencies have not been installed yet, or the script was run in an environment where the node_modules directory is not present or is located elsewhere.

Given this information, it's crucial to address the missing app/containers directory in the alias settings if it's indeed no longer used or was included by mistake. Additionally, the situation with the node_modules directory should be clarified, as its presence is fundamental for resolving node modules.

Analysis chain

Verify the import resolver settings for correctness and compatibility.


Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the correctness of import resolver settings in ESLint configuration.
echo "Check if the import resolver settings align with the project's directory structure and module resolution."

Length of output: 223



Script:

#!/bin/bash
# Verify existence of directories mentioned in the alias settings.
directories=("app/assets" "app/components" "app/containers" "app/config" "app/navigators" "app/services" "app/themes" "app/utils" "app" "node_modules")

for dir in "${directories[@]}"; do
  if [ -d "$dir" ]; then
    echo "$dir exists."
  else
    echo "$dir does not exist."
  fi
done

Length of output: 1249

}
}
}
}
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ buck-out/
.expo/
web-build/
dist/
ios
android
4 changes: 1 addition & 3 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ if (!window.Intl) {
})
.then(() => Promise.all([import('intl/locale-data/jsonp/en.js')]))
.then(() => AppRegistry.registerComponent(appName, () => App))
.catch(err => {
throw err;
});
.catch(alert);
} else {
AppRegistry.registerComponent(appName, () => App);
}
Expand Down
Binary file removed android/app/my-upload-key.keystore
Binary file not shown.
3 changes: 3 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"android": {
"package": "com.wednesdaysolutions.rntws"
},
"ios": {
"bundleIdentifier": "com.wednesdaysolutions.rntws"
}
}
}
11 changes: 5 additions & 6 deletions app/components/atoms/LanguageProvider/actions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
*
* LanguageProvider actions
*
*/

import { CHANGE_LOCALE } from './constants';

/**
* Description
* @param {any} languageLocale
* @returns {any}
*/
export function changeLocale(languageLocale) {
return {

Check warning on line 9 in app/components/atoms/LanguageProvider/actions.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹 Function is not covered

Warning! Not covered function
type: CHANGE_LOCALE,
locale: languageLocale
};
}

Check warning on line 13 in app/components/atoms/LanguageProvider/actions.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
10 changes: 10 additions & 0 deletions app/components/atoms/LanguageProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { IntlProvider } from 'react-intl';

import { makeSelectLocale } from './selectors';

/**
* Description
* @param {any} props
* @returns {any}
*/
export function LanguageProvider(props) {
return (
<IntlProvider
Expand All @@ -36,6 +41,11 @@ const mapStateToProps = createSelector(makeSelectLocale(), locale => ({
locale
}));

/**
* Description
* @param {any} dispatch
* @returns {any}
*/
function mapDispatchToProps(dispatch) {
return {
dispatch
Expand Down
11 changes: 5 additions & 6 deletions app/components/atoms/LanguageProvider/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export const initialState = fromJS({
/* eslint-disable default-case, no-param-reassign */
export const languageProviderReducer = (state = initialState, action) =>
produce(state, (/* draft */) => {
switch (action.type) {
case languageProviderTypes.CHANGE_LOCALE:
return state.set('locale', action.locale);
default:
return state;
}
const actionType = {
[languageProviderTypes.CHANGE_LOCALE]: () =>
state.set('locale', action.locale)
};
return action.type in actionType ? actionType[action.type]() : state;
});

export default languageProviderReducer;
19 changes: 8 additions & 11 deletions app/components/atoms/LanguageProvider/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import React from 'react';
import 'react-native';
import { render } from '@testing-library/react-native';
import { Provider } from 'react-redux';
import T from '@atoms/T';
import createStore from 'app/rootReducer';
import { translationMessages } from 'app/i18n';
import { renderWithIntl } from '@utils/testUtils';
import ConnectedLanguageProvider, { LanguageProvider } from '../index';

import { Text } from 'react-native';
describe('<LanguageProvider /> container tests', () => {
it('should render its children', () => {
const children = <h1>Test</h1>;
const children = (
<h1>
<Text>Test</Text>
</h1>
);
const container = renderWithIntl(
<LanguageProvider messages={translationMessages} locale="en">
{children}
Expand All @@ -19,16 +22,10 @@ describe('<LanguageProvider /> container tests', () => {
expect(container.firstChild).not.toBeNull();
});
});

const setupReduxStore = () => ({ reduxStore: createStore().store });
describe('<ConnectedLanguageProvider /> container tests', () => {
let reduxStore;

beforeAll(() => {
const { store } = createStore();
reduxStore = store;
});

it('should render the default language messages', () => {
const { reduxStore } = setupReduxStore();
const { queryByText } = render(
<Provider store={reduxStore}>
<ConnectedLanguageProvider messages={translationMessages}>
Expand Down
13 changes: 5 additions & 8 deletions app/components/atoms/LanguageProvider/tests/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ import {
languageProviderTypes,
languageProviderReducer
} from '../reducer';

const setupMockedState = () => ({ mockedState: initialState });
/* eslint-disable default-case, no-param-reassign */
describe('Tests for LanguageProvider actions', () => {
let mockedState;
beforeEach(() => {
mockedState = initialState;
});

it('returns the initial state', () => {
const { mockedState } = setupMockedState();
expect(languageProviderReducer(undefined, {})).toEqual(mockedState);
});

it('changes the locale', () => {
const { mockedState } = setupMockedState();
const locale = 'de';
mockedState = mockedState.set('locale', locale);
const UpdateMockedState = mockedState.set('locale', locale);
expect(
languageProviderReducer(undefined, {
type: languageProviderTypes.CHANGE_LOCALE,
locale
})
).toEqual(mockedState);
).toEqual(UpdateMockedState);
});
});
5 changes: 5 additions & 0 deletions app/components/molecules/CharacterWithQuote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const CharacterImage = styled.Image`
margin: 0 auto;
`;

/**
* Description
* @param {any} {user}
* @returns {any}
*/
function CharacterWithQuote({ user }) {
return (
<>
Expand Down
23 changes: 13 additions & 10 deletions app/components/molecules/If/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
*
*/
// eslint-disable-next-line
import React from 'react'
import Proptypes from 'prop-types';
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

If.propTypes = {
condition: PropTypes.bool,
otherwise: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
]),
children: Proptypes.oneOfType([
Proptypes.arrayOf(Proptypes.node),
Proptypes.node
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
])
};

If.defaultProps = {
otherwise: null
};

export default If;
4 changes: 2 additions & 2 deletions app/components/molecules/If/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ describe('<If />', () => {
</If>
);
expect(getByText(conditionTrueText)).toBeTruthy();
props.condition = false;
const falseProps = { ...props, condition: false };
const { getByText: textQueryOnReRender } = render(
<If {...props}>
<If {...falseProps}>
<TrueConditionComponent />
</If>
);
Expand Down
Loading
Loading