Skip to content

Commit

Permalink
Configure linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidmt committed Apr 10, 2019
1 parent 7d547e4 commit 7a19b19
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 147 deletions.
125 changes: 1 addition & 124 deletions .markdownlintrc
Original file line number Diff line number Diff line change
@@ -1,126 +1,3 @@
{
"default": true,

/*
* MD001 - Header levels should only increment by one level at a time
*/
"header-increment": true,

/*
* MD002 - First header should be a top level header
*/
"first-header-h1": {
"level": 1
},

/*
* MD003 - Header style
*
* Triggered when different header styles (atx, setext, and 'closed' atx)
* are used in the same document:
*
* # ATX style H1
*
* ## Closed ATX style H2 ##
*
* Setext style H1
* ===============
*/
"header-style": {
// Values: "consistent", "atx", "atx_closed", "setext",
// "setext_with_atx", "setext_with_atx_closed";
//
// Default: "consistent"
"style": "atx"
},
/*
* MD004 - Unordered list style
*
* Triggered when the symbols used in the document for unordered list
* items do not match the configured unordered list style:
*
* * Item 1
* + Item 2
* - Item 3
*/
"ul-style": {
// Values: "consistent", "asterisk", "plus", "dash", "sublist";
// Default: "consistent"
"style": "consistent"
},

/*
* MD005 - Inconsistent indentation for list items at the same level
*
* Triggered when list items are parsed as being at the same level, but
* don't have the same indentation:
*
* * Item 1
* * Nested Item 1
* * Nested Item 2
* * A misaligned item
*/
"list-indent": true,

/*
* MD006 - Consider starting bulleted lists at the beginning of the line
*
* Triggered when top level lists don't start at the beginning of a line:
*
* Some text
*
* * List item
* * List item
*/
"ul-start-left": true,

/*
* MD007 - Unordered list indentation
*
* Triggered when list items are not indented by the configured number of
* spaces.
*/
"ul-indent": {
// Default: 2
"indent": 4
},

/*
* MD009 - Trailing spaces
*
* Triggered on any lines that end with whitespace.
*/
"no-trailing-spaces": {
// Allows an exception to this rule for a specific amount of trailing
// spaces used to insert an explicit line break/br element. For
// example, set br_spaces to 2 to allow exactly 2 spaces at the end of
// a line.
"br_spaces": 2,

// Using spaces to indent blank lines inside a list item is usually
// not necessary, but some parsers require it. Set the
// list_item_empty_lines parameter to true to allow this.
"list_item_empty_lines": true
},

/*
* MD013 - Line length
*
* Triggered when there are lines that are longer than the configured line
* length (default: 80 characters). To fix this, split the line up into
* multiple lines.
*/
"line-length": {
"line_length": 400,
"headers": 80
},

/*
* MD024 - Multiple headers with the same content
*
* Triggered if there are multiple headers in the document that have the
* same text.
*/

"no-duplicate-header": true
"default": true
}
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Add

- Can add "beforeSend" middleware
- Can add "beforeSend" middleware
- Diagrams and words describing how things work

## [0.5.5] - 7 February 2019
Expand All @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Change

- JSON stringify based on route response type
- JSON stringify based on route response type

## [0.5.3] - 7 February 2019

Expand All @@ -50,7 +50,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Add

- Add Prometheus metrics support via `/metrics`
- Add Prometheus metrics support via `/metrics`

## [0.4.3] - 15 January 2019

Expand Down
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- markdownlint-disable line-length -->
<!-- markdownlint-disable first-line-h1 line-length -->

[![npm package version](https://badge.fury.io/js/%40asd14%2Fblocks.svg)](https://badge.fury.io/js/%40asd14%2Fblocks)
[![Coverage Status](https://coveralls.io/repos/github/asd14/blocks/badge.svg)](https://coveralls.io/github/asd14/blocks)

Expand All @@ -12,6 +13,9 @@
<!-- vim-markdown-toc GFM -->

* [Features](#features)
* [Validate input](#validate-input)
* [Permissions](#permissions)
* [Async support](#async-support)
* [Install](#install)
* [Basic example](#basic-example)
* [Routes](#routes)
Expand All @@ -29,19 +33,19 @@

## Features

__Validate input__
### Validate input

> Pass request data (headers, body, query parameters, URL parameters) through custom JSON Schemas defined for each route. Make sure no unwanted data gets in, de-clutter the route logic and make the API behave more consistent.
If validation fails, an automatic `409 Conflict` response will be sent to the client.

See [`ajv`](https://github.com/epoberezkin/ajv) and [JSON Schema docs](https://json-schema.org) for more on data validation.

__Permissions__
### Permissions

> Simple function outside of main route logic.
If it returns false, an automatic `403 Forbidden` response will be sent to the client.

__Async support__
### Async support

> Route actions, middleware and plugins have `async/await` support.
Expand All @@ -56,7 +60,7 @@ Other:
npm i @asd14/blocks
```

## Basic example
## Basic example

`src/index.js`

Expand Down Expand Up @@ -88,15 +92,15 @@ block({

### Default "/ping" route

`GET: /ping`
`GET: /ping`

```js
{
"ping": "pong",
"aliveFor": {
"days": 2, "hours": 1, "minutes": 47, "seconds": 46
},
"version": "0.5.6",
"version": "0.5.6",
}
```

Expand All @@ -109,21 +113,21 @@ module.exports = {
method: "GET",
path: "/something",

// If req data is valid
// -> continue to permissionn check
// If req data is valid
// -> continue to permissionn check
// -> otherwise return 409
schema: require("./something.schema"),

// If allowed
// -> continue to action
// If allowed
// -> continue to action
// -> otherwise return 403
isAllowed: (/* plugins */) => async ({ method, ctx }) => {
console.log(`${method}:${ctx.pathname} - isAllowed`)

return true
},

// Returned value will be set in `res` body
// Returned value will be set in `res` body
action: (/* plugins */) => async (/* req */) => {
return {
message: "This is something else!"
Expand Down Expand Up @@ -173,7 +177,7 @@ While you can use `process.env` to access CI variables globally, use this opport
```js
blocks({
settings: {
// (CI) Key to verify incoming json-web-tokens. See `src/middleware/req-jwt.js`
// (CI) Key to verify incoming json-web-tokens. See `src/middleware/req-jwt.js`
JWT_SECRET: process.env.JWT_SECRET ?? "CHANGE ME!"
...
},
Expand Down Expand Up @@ -206,7 +210,7 @@ module.exports = {
// Array of plugins to wait for before running `create`
depend: ["Config"],

/**
/**
* Constructor, return value will be considered the plugin's content exposed
* to routes, middleware and other plugins.
*
Expand All @@ -217,7 +221,7 @@ module.exports = {
*/
create: (/* props */) => Config => {
console.log("Checking DB connection")

// Database connection, model loading etc
...
return {
Expand Down Expand Up @@ -256,6 +260,5 @@ History of all changes in [CHANGELOG.md](/CHANGELOG.md)
#### Add
- Can add "beforeSend" middleware
- Diagrams and words describing how things work
* Can add "beforeSend" middleware
* Diagrams and words describing how things work
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
"build": "babel src -d lib",
"prepare": "npm audit fix && npm test && npm run lint && npm run build",
"prepublishOnly": "npm run coverage",
"----LINT-------------------------------------": "",
"lint:js": "eslint --ext .js src/",
"lint:md": "markdownlint *.md",
"lint": "npm run lint:md && npm run lint:js",
"----TEST-------------------------------------": "",
"lint": "eslint src",
"test": "tape -r @babel/register examples/**/*.test.js",
"tdd": "nodemon --watch src --watch examples --exec \"npm test | tap-diff\""
"tdd": "nodemon --watch src --watch examples --exec \"npm test | tap-diff\"",
"coverage:report": "NODE_ENV=test nyc npm test && nyc report --reporter=html",
"coverage": "NODE_ENV=test nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"keywords": [],
"author": {
Expand Down

0 comments on commit 7a19b19

Please sign in to comment.