Skip to content

Commit da8af44

Browse files
authored
feat: enforce action.type (#36)
- action.type must be a string or Symbol (the latter may or may not be dropped, so test support can also be removed easily) - use npm scripts instead of Makefile - use Babel 6 - use nyc for code coverage and coveralls - test against latest versions of Node LTS - add editorconfig - upgrade all dependencies except eslint-plugin-import - Remove unnecessary test helper - Add yarn.lock
1 parent 9634938 commit da8af44

File tree

14 files changed

+3297
-61
lines changed

14 files changed

+3297
-61
lines changed

.babelrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2-
"stage": 0,
3-
"loose": "all"
2+
"presets": ["stage-0", ["es2015", { "loose": true }]],
3+
"env": {
4+
"test": {
5+
"plugins": ["istanbul"]
6+
}
7+
}
48
}

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
5+
# Change these settings to your own preference
6+
indent_style = space
7+
indent_size = 2
8+
9+
# We recommend you to keep these unchanged
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "eslint-config-airbnb",
2+
"extends": "eslint-config-airbnb-base",
33
"env": {
44
"mocha": true,
55
"node": true
@@ -8,8 +8,8 @@
88
"expect": true
99
},
1010
"rules": {
11-
"padded-blocks": 0,
12-
"no-use-before-define": [2, "nofunc"],
13-
"no-unused-expressions": 0
11+
"no-use-before-define": 0,
12+
"no-unused-expressions": 0,
13+
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["!test/**/*.js"]}]
1414
}
1515
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
coverage
33
*.log
44
lib
5+
.idea
6+
.nyc_output

.npmignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
sudo: false
12
language: node_js
23
node_js:
3-
- "iojs"
4+
- "stable"
5+
- 4
6+
7+
after_success: "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"

Makefile

Lines changed: 0 additions & 24 deletions
This file was deleted.

package.json

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
"version": "0.6.1",
44
"description": "A human-friendly standard for Flux action objects",
55
"main": "lib/index.js",
6+
"files": [
7+
"lib"
8+
],
69
"scripts": {
7-
"test": "make test",
8-
"prepublish": "make clean build"
10+
"prebuild": "npm run clean",
11+
"build": "babel src --out-dir lib",
12+
"clean": "rimraf lib/",
13+
"lint": "eslint src/ test/",
14+
"prepublish": "npm test && npm run build",
15+
"pretest": "npm run lint",
16+
"test": "cross-env NODE_ENV=test nyc mocha"
917
},
1018
"keywords": [
1119
"flux",
@@ -16,15 +24,39 @@
1624
"author": "Andrew Clark <[email protected]>",
1725
"license": "MIT",
1826
"devDependencies": {
19-
"babel": "^5.6.14",
20-
"babel-core": "^5.6.15",
21-
"babel-eslint": "^4.1.8",
27+
"babel-cli": "^6.16.0",
28+
"babel-core": "^6.17.0",
29+
"babel-eslint": "^7.0.0",
30+
"babel-plugin-istanbul": "^2.0.1",
31+
"babel-preset-es2015": "^6.16.0",
32+
"babel-preset-stage-0": "^6.16.0",
2233
"chai": "^3.0.0",
23-
"eslint": "^0.24.0",
24-
"eslint-config-airbnb": "0.0.6",
25-
"mocha": "^2.2.5"
34+
"coveralls": "^2.11.14",
35+
"cross-env": "^3.1.1",
36+
"eslint": "^3.7.1",
37+
"eslint-config-airbnb-base": "^8.0.0",
38+
"eslint-plugin-import": "^1.0.0",
39+
"mocha": "^3.0.0",
40+
"nyc": "^8.3.0",
41+
"rimraf": "^2.5.4"
2642
},
2743
"dependencies": {
28-
"lodash.isplainobject": "^3.2.0"
44+
"lodash.isplainobject": "^4.0.6",
45+
"lodash.isstring": "^4.0.1",
46+
"lodash.issymbol": "^4.0.1"
47+
},
48+
"nyc": {
49+
"all": true,
50+
"sourceMap": false,
51+
"instrument": false,
52+
"reporter": [
53+
"text-summary",
54+
"lcov"
55+
],
56+
"check-coverage": true,
57+
"lines": 100,
58+
"statements": 100,
59+
"functions": 100,
60+
"branches": 100
2961
}
3062
}

src/__tests__/init.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import isPlainObject from 'lodash.isplainobject';
2-
3-
const validKeys = [
4-
'type',
5-
'payload',
6-
'error',
7-
'meta'
8-
];
9-
10-
function isValidKey(key) {
11-
return validKeys.indexOf(key) > -1;
12-
}
2+
import isString from 'lodash.isstring';
3+
import isSymbol from 'lodash.issymbol';
134

145
export function isFSA(action) {
156
return (
167
isPlainObject(action) &&
17-
typeof action.type !== 'undefined' &&
8+
(isString(action.type) || isSymbol(action.type)) &&
189
Object.keys(action).every(isValidKey)
1910
);
2011
}
2112

2213
export function isError(action) {
2314
return action.error === true;
2415
}
16+
17+
function isValidKey(key) {
18+
return [
19+
'type',
20+
'payload',
21+
'error',
22+
'meta',
23+
].indexOf(key) > -1;
24+
}

src/__tests__/isError-test.js renamed to test/isError-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { isError } from '../';
1+
import { expect } from 'chai';
2+
import { isError } from '../src/';
23

34
const type = 'ACTION_TYPE';
45

src/__tests__/isFSA-test.js renamed to test/isFSA-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { isFSA } from '../';
1+
import { expect } from 'chai';
2+
import { isFSA } from '../src/';
23

34
const type = 'ACTION_TYPE';
5+
const symbolType = Symbol.for(type);
46

57
describe('isFSA()', () => {
68
it('requires a type', () => {
79
expect(isFSA({ type })).to.be.true;
10+
expect(isFSA()).to.be.false;
11+
expect(isFSA({})).to.be.false;
12+
expect(isFSA({ type: undefined })).to.be.false;
813
});
914

1015
it('only accepts plain objects', () => {
@@ -13,6 +18,13 @@ describe('isFSA()', () => {
1318
expect(isFSA(action)).to.be.false;
1419
});
1520

21+
it('only returns true if type is a string or symbol', () => {
22+
// remove this assertion if/when symbol support is dropped
23+
expect(isFSA({ type: symbolType })).to.be.true;
24+
expect(isFSA({ type: true })).to.be.false;
25+
expect(isFSA({ type: 123 })).to.be.false;
26+
});
27+
1628
it('returns false if there are invalid keys', () => {
1729
expect(isFSA({ type, payload: 'foobar' })).to.be.true;
1830
expect(isFSA({ type, meta: 'foobar' })).to.be.true;

test/mocha.opts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--compilers js:babel-core/register
2+
--recursive

0 commit comments

Comments
 (0)