Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
style: format all with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysova committed Dec 9, 2018
1 parent 0729e14 commit b2794f0
Show file tree
Hide file tree
Showing 107 changed files with 1,842 additions and 1,850 deletions.
76 changes: 43 additions & 33 deletions .cz-config.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,80 @@
const glob = require('glob')
const glob = require("glob")

/**
* @param {string} pattern
* @param {(path: string) => string} fn
*/
const globMap = (pattern, fn) => glob
.sync(pattern)
.map(fn || ((path) => path))
.map((path) => path.replace(/\/$/, ''))
const globMap = (pattern, fn) =>
glob
.sync(pattern)
.map(fn || ((path) => path))
.map((path) => path.replace(/\/$/, ""))

/**
* Check `path` to not include substring in `variants`
* @param {string[]} variants
* @return {(path: string) => boolean}
*/
const exclude = (variants) => (path) => variants.every((variant) => !path.includes(variant))
const exclude = (variants) => (path) =>
variants.every((variant) => !path.includes(variant))

/**
* Check `path` to include substring of one of `variants`
* @param {string[]} variants
* @return {(path: string) => boolean}
*/
const include = (variants) => (path) => variants.some((variant) => path.includes(variant))
const include = (variants) => (path) =>
variants.some((variant) => path.includes(variant))

module.exports = {
types: [
{ value: 'feat', name: 'feat: A new feature' },
{ value: 'fix', name: 'fix: A bug fix' },
{ value: 'docs', name: 'docs: Documentation only changes' },
{ value: "feat", name: "feat: A new feature" },
{ value: "fix", name: "fix: A bug fix" },
{ value: "docs", name: "docs: Documentation only changes" },
{
value: 'style',
value: "style",
name:
'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
"style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)",
},
{
value: 'chore',
value: "chore",
name:
'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation',
"chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation",
},
{
value: 'config',
name: 'config: Changes in configuration files. Add new or remove old.',
value: "config",
name: "config: Changes in configuration files. Add new or remove old.",
},
{
value: 'refactor',
name: 'refactor: A code change that neither fixes a bug nor adds a feature',
value: "refactor",
name:
"refactor: A code change that neither fixes a bug nor adds a feature",
},
{
value: 'perf',
name: 'perf: A code change that improves performance',
value: "perf",
name: "perf: A code change that improves performance",
},
{ value: 'test', name: 'test: Adding missing tests' },
{ value: 'revert', name: 'revert: Revert to a commit' },
{ value: 'WIP', name: 'WIP: Work in progress' },
{ value: "test", name: "test: Adding missing tests" },
{ value: "revert", name: "revert: Revert to a commit" },
{ value: "WIP", name: "WIP: Work in progress" },
],
scopes: [].concat(
'app',
globMap('src/*/', (path) => path.replace(/src\//, '')).filter(exclude(['features', 'ui'])),
'features',
globMap('src/features/*/', (path) => path.replace('src/', '')),
globMap('src/features/*/features/*', (path) => path.replace('src/', '').replace(/\/features\//, '/')),
'ui',
globMap('src/ui/*/', (path) => path.replace(/^src\//, '')),
'server',
globMap('mock-server/server/*/**/', (path) => path.replace(/mock\-server\//, ''))
"app",
globMap("src/*/", (path) => path.replace(/src\//, "")).filter(
exclude(["features", "ui"]),
),
"features",
globMap("src/features/*/", (path) => path.replace("src/", "")),
globMap("src/features/*/features/*", (path) =>
path.replace("src/", "").replace(/\/features\//, "/"),
),
"ui",
globMap("src/ui/*/", (path) => path.replace(/^src\//, "")),
"server",
globMap("mock-server/server/*/**/", (path) =>
path.replace(/mock\-server\//, ""),
),
),
allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix', 'revert'],
allowBreakingChanges: ["feat", "fix", "revert"],
}
9 changes: 6 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"parser": "babel-eslint",
"plugins": [
"jest"
"jest",
"prettier"
],
"extends": ["plugin:jest/recommended", "@atomix/eslint-config"],
"extends": ["plugin:jest/recommended", "@atomix/eslint-config", "plugin:prettier/recommended"],
"env": {
"browser": true,
"es6": true
Expand All @@ -13,6 +14,8 @@
"functions": false,
"classes": true,
"variables": true
}]
}],
"import/newline-after-import": ["error", { "count": 1 }],
"quotes": "off"
}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
24 changes: 12 additions & 12 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
module.exports = {
presets: [
[
'@babel/env',
"@babel/env",
{
modules: false,
useBuiltIns: 'usage',
useBuiltIns: "usage",
},
],
'@babel/react',
"@babel/react",
],
plugins: [
['@babel/plugin-proposal-class-properties', { loose: false }],
'@babel/proposal-export-namespace-from',
'@babel/syntax-dynamic-import',
'@babel/plugin-proposal-json-strings',
["@babel/plugin-proposal-class-properties", { loose: false }],
"@babel/proposal-export-namespace-from",
"@babel/syntax-dynamic-import",
"@babel/plugin-proposal-json-strings",
],
env: {
production: {
plugins: [
'@babel/transform-react-constant-elements',
'@babel/transform-react-inline-elements',
"@babel/transform-react-constant-elements",
"@babel/transform-react-inline-elements",
[
'transform-react-remove-prop-types',
"transform-react-remove-prop-types",
{
removeImport: true,
},
Expand All @@ -33,11 +33,11 @@ module.exports = {
development: {
plugins: [
// 'react-hot-loader/babel',
'styled-name',
"styled-name",
],
},
test: {
presets: [['@babel/env'], '@babel/react'],
presets: [["@babel/env"], "@babel/react"],
},
},
}
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
// collectCoverageFrom: null,

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
coverageDirectory: "coverage",

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
Expand Down Expand Up @@ -125,7 +125,7 @@ module.exports = {
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: 'node',
testEnvironment: "node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
Expand Down
11 changes: 2 additions & 9 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
"baseUrl": "./src",
"checkJs": false,
"jsx": "react",
"lib": [
"es2015",
"es2016",
"dom"
],
"lib": ["es2015", "es2016", "dom"],
"paths": {
"@features/*": ["./features/*"],
"@ui/*": ["./ui/*"],
"@lib/*": ["./lib/*"]
}
},
"exclude": [
"node_modules",
"dist"
]
"exclude": ["node_modules", "dist"]
}
6 changes: 4 additions & 2 deletions mock-server/bin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node
/* eslint-disable import/no-extraneous-dependencies, no-console */

require('@babel/register')({ extensions: ['.js', '.mjs'] })
require('./server').main().catch(console.error)
require("@babel/register")({ extensions: [".js", ".mjs"] })
require("./server")
.main()
.catch(console.error)
11 changes: 5 additions & 6 deletions mock-server/server/api/errors.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@

export class CustomError extends Error {}

export class EmptyResultError extends CustomError {
constructor() {
super('empty_result')
super("empty_result")
this.httpStatus = 204
}
}

export class InternalServerError extends CustomError {
constructor(error) {
super('internal_server_error')
super("internal_server_error")
this.message = error
this.httpStatus = 500
}
}

export class ValidationError extends CustomError {
constructor(formErrors) {
super('validation_error')
super("validation_error")
this.message = formErrors
this.httpStatus = 400
}
}

export class AuthorizationError extends CustomError {
constructor(text = 'invalid_authorization') {
constructor(text = "invalid_authorization") {
super(text)
this.httpStatus = 401
}
}

export class NotFoundError extends CustomError {
constructor(type = 'not_found') {
constructor(type = "not_found") {
super(type)
this.httpStatus = 404
}
Expand Down
15 changes: 7 additions & 8 deletions mock-server/server/api/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import { printRoutes as printRestRoutes, createRest } from 'createrest'
import { createKoaRouter } from 'createrest-koa'

import { apiWrapper } from './middlewares/api-wrapper'
import { rootApi } from './routes'
import './rpc'
import Koa from "koa"
import bodyParser from "koa-bodyparser"
import { printRoutes as printRestRoutes, createRest } from "createrest"
import { createKoaRouter } from "createrest-koa"

import { apiWrapper } from "./middlewares/api-wrapper"
import { rootApi } from "./routes"
import "./rpc"

export const api = new Koa()

Expand Down
22 changes: 10 additions & 12 deletions mock-server/server/api/middlewares/api-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Future from 'fluture'
import { EmptyResultError, InternalServerError, CustomError } from '../errors'

import Future from "fluture"
import { EmptyResultError, InternalServerError, CustomError } from "../errors"

const STATUS_OK = 200
// const STATUS_NO_CONTENT = 204
Expand All @@ -21,7 +20,10 @@ export const apiWrapper = () => async (ctx, next) => {
.mapRej((error) => ({
ok: false,
error: error.message || error.name || error,
status: statusDefaultOr(ctx.status, error.httpStatus || STATUS_BAD_REQUEST),
status: statusDefaultOr(
ctx.status,
error.httpStatus || STATUS_BAD_REQUEST,
),
}))
.chainRej(Future.of)

Expand All @@ -36,8 +38,7 @@ export const apiWrapper = () => async (ctx, next) => {
const resolveMiddlewareToFuture = async (ctx, next) => {
try {
return Future.resolve(await next())
}
catch (error) {
} catch (error) {
if (error instanceof CustomError) {
return Future.reject(error)
}
Expand All @@ -49,14 +50,11 @@ const resolveMiddlewareToFuture = async (ctx, next) => {
}

const emptyToError = (result) => {
if (typeof result === 'undefined' || result === null) {
if (typeof result === "undefined" || result === null) {
return Future.reject(new EmptyResultError())
}
return result
}

const statusDefaultOr = (currentStatus, defaultStatus) => (
currentStatus === STATUS_NOT_IMPLEMENTED
? defaultStatus
: currentStatus
)
const statusDefaultOr = (currentStatus, defaultStatus) =>
currentStatus === STATUS_NOT_IMPLEMENTED ? defaultStatus : currentStatus
Loading

0 comments on commit b2794f0

Please sign in to comment.