Skip to content

Commit

Permalink
Eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Canciller committed Mar 26, 2022
1 parent 75499f4 commit f2dca5d
Show file tree
Hide file tree
Showing 76 changed files with 1,296 additions and 212 deletions.
12 changes: 12 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
src/constants/Permissions.ts
src/types/Levita.d.ts

*.ignore
lib

.eslintrc.js
babel.config.js
cucumber.js
jest.config.js
jest.setup.js
metro.config.js
100 changes: 100 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-native/all',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
settings: {
react: {
version: 'detect',
},
'import/resolver': {
typescript: {},
},
'import/ignore': ['node_modules/react-native/index\\.js$'],
},
plugins: ['react', 'react-native', '@typescript-eslint'],
rules: {
// eslint
'no-empty-pattern': 'off',
'prefer-const': 'off',
'no-constant-condition': 'off',
'no-empty': 'off',
'no-unused-vars': 'off',

// react
'react/prop-types': 'off',
'react/display-name': 'off',
'react/no-unescaped-entities': 'off',

// react-native
'react-native/no-raw-text': 'off',
'react-native/no-inline-styles': 'off',
'react-native/no-color-literals': 'off',
'react-native/no-unused-styles': 'off',
'react-native/sort-styles': 'off',
'react-native/split-platform-components': 'off',

// typescript
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
},
],

// import
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/order': [
'warn',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling'],
pathGroups: [
{
pattern: 'react',
group: 'builtin',
},
{
pattern: 'react-native',
group: 'builtin',
},
{
pattern: '~/**',
group: 'internal',
position: 'after',
},
],
'newlines-between': 'always',
pathGroupsExcludedImportTypes: ['builtin'],
alphabetize: {
order: 'asc',
},
},
],
},
};
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src/constants/Permissions.ts
src/types/Levita.d.ts

*.ignore
lib
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
bracketSameLine: false,
singleQuote: true,
trailingComma: 'all',
semi: true,
arrowParens: 'avoid',
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
31 changes: 27 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0",
"private": true,
"workspaces": [
"example",
"packages/*"
"example",
"packages/*"
],
"scripts": {
"start": "yarn workspace example start",
Expand All @@ -14,7 +14,30 @@
"publish:theme": "yarn workspace @nomada-sh/react-native-eyecandy-theme publish",
"publish:icons": "yarn workspace @nomada-sh/react-native-eyecandy-icons publish",
"publish:components": "yarn workspace @nomada-sh/react-native-eyecandy publish",
"build": "yarn build:theme && yarn build:icons && yarn build:components"
"build": "yarn build:theme && yarn build:icons && yarn build:components",
"lint:theme": "eslint packages/react-native-eyecandy-theme",
"lint:fix:theme": "eslint packages/react-native-eyecandy-theme --fix",
"lint:icons": "eslint packages/react-native-eyecandy-icons",
"lint:fix:icons": "eslint packages/react-native-eyecandy-icons --fix",
"lint:components": "eslint packages/react-native-eyecandy",
"lint:fix:components": "eslint packages/react-native-eyecandy --fix",
"lint:example": "eslint example",
"lint:fix:example": "eslint example --fix",
"lint": "yarn lint:theme && yarn lint:icons && yarn lint:components && yarn lint:example",
"lint:fix": "yarn lint:fix:theme && yarn lint:fix:icons && yarn lint:fix:components && yarn lint:fix:example"
},
"devDependencies": {}
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^2.7.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-react-native": "^4.0.0",
"prettier": "^2.6.1",
"typescript": "^4.5.5"
}
}
2 changes: 1 addition & 1 deletion packages/react-native-eyecandy-icons/src/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import Svg, { SvgProps } from 'react-native-svg';

import {
useColors,
ThemeTextColorsChoices,
} from '@nomada-sh/react-native-eyecandy-theme';
import Svg, { SvgProps } from 'react-native-svg';

export interface IconProps extends Omit<SvgProps, 'color'> {
size?: number;
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-eyecandy-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"source": "src/index.ts",
"scripts": {
"prepare": "bob build",
"build": "bob build",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"publish": "npm publish --access public",
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native-eyecandy-theme/src/colors/createColors.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CreateThemeColors } from './types';
import { createPalette } from '../palette';
import { createTypography } from '../typography';

import getBackgroundColors from './getBackgroundColors';
import getBadgeColors from './getBadgeColors';
import getButtonColors from './getButtonColors';
import getTextColors from './getTextColors';
import getDividerColors from './getDividerColors';
import getInputColors from './getInputColors';
import getSwitchColors from './getSwitchColors';
import getBackgroundColors from './getBackgroundColors';
import getDividerColors from './getDividerColors';
import getBadgeColors from './getBadgeColors';
import getTextColors from './getTextColors';
import { CreateThemeColors } from './types';

const createColors: CreateThemeColors = (options = {}) => {
const variables = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeBackgroundColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { ThemeBackgroundColors, GetThemeColors } from './types';

const getButtonColors: GetThemeColors<ThemeBackgroundColors> = options => {
const { dark, palette } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ThemeDividerColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { GetThemeColors } from './types';

import { ThemeBadgeColors } from '.';

const getDividerColors: GetThemeColors<ThemeBadgeColors> = options => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeButtonColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { ThemeButtonColors, GetThemeColors } from './types';

const getButtonColors: GetThemeColors<ThemeButtonColors> = options => {
const { dark, palette } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeDividerColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { ThemeDividerColors, GetThemeColors } from './types';

const getDividerColors: GetThemeColors<ThemeDividerColors> = options => {
const { dark, palette } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeInputColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { ThemeInputColors, GetThemeColors } from './types';

const getInputColors: GetThemeColors<ThemeInputColors> = options => {
const { dark, palette } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeSwitchColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { ThemeSwitchColors, GetThemeColors } from './types';

const getSwitchColors: GetThemeColors<ThemeSwitchColors> = options => {
const { dark, palette } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeTextColors, GetThemeColors } from './types';
import mergeColors from './mergeColors';
import { ThemeTextColors, GetThemeColors } from './types';

const getTextColors: GetThemeColors<ThemeTextColors> = options => {
const { dark, palette } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import deepmerge from 'deepmerge';

import { MergeThemeColorsOptions } from './types';

export default function mergeColors<T>({
Expand Down
12 changes: 9 additions & 3 deletions packages/react-native-eyecandy-theme/src/colors/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeepPartial } from '../types';
import { CustomThemePalette, ThemePalette } from '../palette';
import { DeepPartial } from '../types';
import { CustomThemeTypography, ThemeTypography } from '../typography';

export type ThemeColors = {
Expand Down Expand Up @@ -142,7 +142,13 @@ export type ThemeDividerColors = {
/**
* Badge
*/
export type ThemeBadgeColorChoices = 'default' | 'primary' | 'error' | 'warning' | 'success' | 'greyout';
export type ThemeBadgeColorChoices =
| 'default'
| 'primary'
| 'error'
| 'warning'
| 'success'
| 'greyout';

export type ThemeBadgeColor = {
border: string;
Expand All @@ -151,4 +157,4 @@ export type ThemeBadgeColor = {

export type ThemeBadgeColors = {
[key in ThemeBadgeColorChoices]: ThemeBadgeColor;
};
};
14 changes: 7 additions & 7 deletions packages/react-native-eyecandy-theme/src/context/useColors.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import useTheme from './useTheme';

import { ThemeColors } from '../colors';

export default function useColors(): ThemeColors;
import useTheme from './useTheme';

export default function useColors<T>(selector: (colors: ThemeColors) => T): T;
function useColors(): ThemeColors;

export default function useColors<T>(
selector?: (colors: ThemeColors) => T,
): T | ThemeColors {
function useColors<T>(selector: (colors: ThemeColors) => T): T;

function useColors<T>(selector?: (colors: ThemeColors) => T): T | ThemeColors {
const theme = useTheme();

if (selector) {
Expand All @@ -17,3 +15,5 @@ export default function useColors<T>(

return theme.colors;
}

export default useColors;
14 changes: 7 additions & 7 deletions packages/react-native-eyecandy-theme/src/context/usePalette.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import useTheme from './useTheme';

import { ThemePalette } from '../palette';

export default function usePalette(): ThemePalette;
import useTheme from './useTheme';

export default function usePalette<T>(
selector: (palette: ThemePalette) => T,
): T;
function usePalette(): ThemePalette;

export default function usePalette<T>(
function usePalette<T>(selector: (palette: ThemePalette) => T): T;

function usePalette<T>(
selector?: (palette: ThemePalette) => T,
): T | ThemePalette {
const theme = useTheme();
Expand All @@ -19,3 +17,5 @@ export default function usePalette<T>(

return theme.palette;
}

export default usePalette;
11 changes: 7 additions & 4 deletions packages/react-native-eyecandy-theme/src/context/useTheme.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useContext } from 'react';

import { ThemeContext } from './ThemeProvider';
import { Theme } from '../themes';

export default function useTheme(): Theme;
import { ThemeContext } from './ThemeProvider';

function useTheme(): Theme;

export default function useTheme<T>(selector: (theme: Theme) => T): T;
function useTheme<T>(selector: (theme: Theme) => T): T;

export default function useTheme<T>(selector?: (theme: Theme) => T): T | Theme {
function useTheme<T>(selector?: (theme: Theme) => T): T | Theme {
const theme = useContext(ThemeContext);

if (selector) {
Expand All @@ -16,3 +17,5 @@ export default function useTheme<T>(selector?: (theme: Theme) => T): T | Theme {

return theme;
}

export default useTheme;
Loading

0 comments on commit f2dca5d

Please sign in to comment.