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 all 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
124 changes: 93 additions & 31 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@

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


const prettierOptions = JSON.parse(
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved
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 = {
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',
'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 +68,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 +97,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']
}
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';

/**
* Changes the locale/language of the application.
* @param {string} languageLocale - The new locale/language to set.
* @returns {object} An action object with type 'CHANGE_LOCALE' and the new locale/language.
*/
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
13 changes: 13 additions & 0 deletions app/components/atoms/LanguageProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import { IntlProvider } from 'react-intl';

import { makeSelectLocale } from './selectors';

/**
* Provides internationalization (i18n) support by wrapping components with an IntlProvider.
* @param {object} props - The props object containing component properties.
* @param {string} props.locale - The locale/language code for internationalization.
* @param {object} props.messages - An object containing locale-specific message translations.
* @param {React.ReactNode} props.children - The child elements/components to be wrapped and rendered.
* @returns {React.ReactNode} A JSX element wrapping the provided child components with IntlProvider.
*/
export function LanguageProvider(props) {
return (
<IntlProvider
Expand All @@ -36,6 +44,11 @@ const mapStateToProps = createSelector(makeSelectLocale(), locale => ({
locale
}));

/**
* Generates and returns an object containing action dispatch functions.
* @param {function} dispatch - The Redux store's dispatch function.
* @returns {object} An object containing action dispatch functions wrapped for use in components.
*/
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;
15 changes: 15 additions & 0 deletions app/components/atoms/LanguageProvider/tests/action.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { changeLocale } from '../actions';
import { CHANGE_LOCALE } from '../constants';

// Test suite for the changeLocale action creator
describe('changeLocale action creator', () => {
it('should create an action to change the locale', () => {
const languageLocale = 'en';
const expectedAction = {
type: CHANGE_LOCALE,
locale: languageLocale
};
const action = changeLocale(languageLocale);
expect(action).toEqual(expectedAction);
});
});
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);
});
});
13 changes: 11 additions & 2 deletions app/components/molecules/CharacterWithQuote/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import styled from 'styled-components/native';
import { get } from 'lodash';
import get from 'lodash/get';
import PropTypes from 'prop-types';
import { fonts } from '@themes';
import T from '@atoms/T';
Expand All @@ -17,13 +17,22 @@ const CharacterImage = styled.Image`
margin: 0 auto;
`;

/**
* A component that displays a character's information along with their quote.
* @param {object} props - The props object containing component properties.
* @param {object} props.user - The user object representing the character's details.
* @param {string} props.user.character - The character's name.
* @param {string} props.user.image - The URL of the character's image.
* @param {string} props.user.quote - The character's quote.
* @returns {React.ReactNode} JSX elements displaying the character's information and quote.
*/
function CharacterWithQuote({ user }) {
return (
<>
<Result
id="wednesday_lover"
values={{
username: get(user, 'character') || 'character'
username: get(user, 'character', 'character')
}}
/>
<Result id="because" />
Expand Down
Loading
Loading