Skip to content

Commit aa96b52

Browse files
Adds prettier functionality and supercedes any ESLint conficts
1 parent 0eb0567 commit aa96b52

File tree

8 files changed

+98
-31
lines changed

8 files changed

+98
-31
lines changed

.eslintrc

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"es6": true,
66
"jest": true
77
},
8-
"extends": ["airbnb-base", "plugin:react/recommended"],
8+
"extends": ["airbnb-base", "plugin:react/recommended", "prettier"],
99
"globals": {
1010
"Atomics": "readonly",
1111
"SharedArrayBuffer": "readonly"
@@ -18,9 +18,9 @@
1818
"ecmaVersion": 2018,
1919
"sourceType": "module"
2020
},
21-
"plugins": ["react"],
21+
"plugins": ["react", "prettier"],
2222
"rules": {
23-
"indent": ["error", 4],
23+
"prettier/prettier": "error",
2424
"no-unused-vars": [
2525
"error",
2626
{
@@ -30,7 +30,6 @@
3030
],
3131
"no-plusplus": "off",
3232
"no-underscore-dangle": "off",
33-
"react/self-closing-comp": "off",
3433
"no-restricted-syntax": ["off", "BinaryExpression[operator='in']"]
3534
}
3635
}

.prettierrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 4,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "all",
8+
"bracketSpacing": true,
9+
"jsxBracketSameLine": false,
10+
"proseWrap": "always"
11+
}

HISTORY.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
21
## Version History
32

3+
**5.0.1**
4+
5+
- Adds eslint and prettier
6+
47
**5.0.0**
5-
Adds support for Mailchimp Groups. See README.md for more details on how to implement.
8+
9+
- Adds support for Mailchimp Groups. See README.md for more details on how to implement.
610

711
**4.0.0**
8-
Gatsby v2 is now default. See README.md for upgrade details.
12+
13+
- Gatsby v2 is now default. See README.md for upgrade details.
914

1015
**3.0.0**
11-
- uses `gatsby-node` and [Webpack DefinePlugin](https://webpack.js.org/plugins/define-plugin/) to extract your Mailchimp API key during _compile time only_, set it to global, then use it to make the http request. Previously, we were importing your entire `gatsby-config` file
16+
17+
- uses `gatsby-node` and [Webpack DefinePlugin](https://webpack.js.org/plugins/define-plugin/) to
18+
extract your Mailchimp API key during _compile time only_, set it to global, then use it to make
19+
the http request. Previously, we were importing your entire `gatsby-config` file
1220

1321
**2.0.0**
14-
- return a promise, not string, from an error'd http request
1522

23+
- return a promise, not string, from an error'd http request
1624

1725
## To do
18-
- ensure MC endpoint is valid
19-
- create basic MC field form (name, email, submit button)
20-
- spec
26+
27+
- ensure MC endpoint is valid
28+
- create basic MC field form (name, email, submit button)
29+
- spec

gatsby-node.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ var onCreateWebpackConfig = function onCreateWebpackConfig(_ref, _ref2) {
1010

1111
var isString = typeof endpoint === 'string';
1212
if (!isString) {
13-
throw 'Mailchimp endpoint required and must be of type string. See repo README for more info.';
13+
throw new Error(
14+
'Mailchimp endpoint required and must be of type string. See repo README for more info.',
15+
);
1416
} else if (endpoint.length < 40) {
15-
throw 'gatsby-plugin-mailchimp: donʼt forget to add your MC endpoint to your gatsby-config file. See README for more info.';
17+
throw new Error(
18+
' gatsby-plugin-mailchimp: donʼt forget to add your MC endpoint to your gatsby-config file. See README for more info.',
19+
);
1620
}
1721

1822
actions.setWebpackConfig({

index.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ function _interopRequireDefault(obj) {
2020
* options, along with any MC list fields as query params
2121
*/
2222

23+
// `param` object avoids CORS issues
24+
// timeout to 3.5s so user isn't waiting forever
25+
// usually occurs w/ privacy plugins enabled
26+
// 3.5s is a bit longer than the time it would take on a Slow 3G connection
2327
var subscribeEmailToMailchimp = function subscribeEmailToMailchimp(url) {
2428
return new Promise(function(resolve, reject) {
25-
// `param` object avoids CORS issues
26-
// timeout to 3.5s so user isn't waiting forever
27-
// usually occurs w/ privacy plugins enabled
28-
// 3.5s is a bit longer than the time it would take on a Slow 3G connection
2929
return (0, _jsonp2.default)(url, { param: 'c', timeout: 3500 }, function(err, data) {
3030
if (err) reject(err);
3131
if (data) resolve(data);
@@ -43,12 +43,12 @@ var subscribeEmailToMailchimp = function subscribeEmailToMailchimp(url) {
4343
var convertListFields = function convertListFields(fields) {
4444
var queryParams = '';
4545
for (var field in fields) {
46-
// If this is a list group, not user field,
47-
// then keep lowercase, as per MC reqs
48-
// Read more: https://github.com/benjaminhoffman/gatsby-plugin-mailchimp/blob/master/README.md#groups
49-
// NOTE: we use `substring` instead of `startsWith` or `includes` bc of compatability (esp IE)
50-
var fieldTransformed = field.substring(0, 6) ? field : field.toUpperCase();
51-
queryParams = queryParams.concat('&' + fieldTransformed + '=' + fields[field]);
46+
if (Object.prototype.hasOwnProperty.call(fields, field)) {
47+
// If this is a list group, not user field then keep lowercase, as per MC reqs
48+
// https://github.com/benjaminhoffman/gatsby-plugin-mailchimp/blob/master/README.md#groups
49+
var fieldTransformed = field.substring(0, 6) ? field : field.toUpperCase();
50+
queryParams = queryParams.concat('&' + fieldTransformed + '=' + fields[field]);
51+
}
5252
}
5353
return queryParams;
5454
};
@@ -72,7 +72,8 @@ var addToMailchimp = function addToMailchimp(email, fields) {
7272
// generate Mailchimp endpoint for jsonp request
7373
// note, we change `/post` to `/post-json`
7474
// otherwise, Mailchomp returns an error
75-
var endpoint = window.__GATSBY_PLUGIN_MAILCHIMP_ADDRESS__.replace(/\/post/g, '/post-json');
75+
// eslint-disable-next-line no-undef
76+
var endpoint = __GATSBY_PLUGIN_MAILCHIMP_ADDRESS__.replace(/\/post/g, '/post-json');
7677

7778
var queryParams = '&EMAIL=' + emailEncoded + convertListFields(fields);
7879
var url = '' + endpoint + queryParams;

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gatsby-plugin-mailchimp",
33
"author": "Benjamin Hoffman <[email protected]>",
4-
"version": "5.0.0",
4+
"version": "5.0.1",
55
"description": "A simple, lightweight Gatsby plugin to subscribe email addresses to your Mailchimp list",
66
"main": "index.js",
77
"license": "MIT",
@@ -37,10 +37,13 @@
3737
"babel-preset-env": "^1.7.0",
3838
"eslint": "^5.16.0",
3939
"eslint-config-airbnb-base": "^13.1.0",
40+
"eslint-config-prettier": "^4.2.0",
4041
"eslint-plugin-import": "^2.17.2",
42+
"eslint-plugin-prettier": "^3.0.1",
4143
"eslint-plugin-react": "^7.12.4",
4244
"husky": "^2.1.0",
4345
"lint-staged": "^8.1.5",
46+
"prettier": "^1.17.0",
4447
"webpack": "^4.29.6"
4548
},
4649
"husky": {
@@ -51,6 +54,7 @@
5154
"lint-staged": {
5255
"*.js": [
5356
"eslint --fix",
57+
"prettier --write",
5458
"git add"
5559
]
5660
}

src/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import { validate } from 'email-validator';
1111
// timeout to 3.5s so user isn't waiting forever
1212
// usually occurs w/ privacy plugins enabled
1313
// 3.5s is a bit longer than the time it would take on a Slow 3G connection
14-
const subscribeEmailToMailchimp = url => new Promise((resolve, reject) => jsonp(url, { param: 'c', timeout: 3500 }, (err, data) => {
15-
if (err) reject(err);
16-
if (data) resolve(data);
17-
}));
14+
const subscribeEmailToMailchimp = url =>
15+
new Promise((resolve, reject) =>
16+
jsonp(url, { param: 'c', timeout: 3500 }, (err, data) => {
17+
if (err) reject(err);
18+
if (data) resolve(data);
19+
}),
20+
);
1821

1922
/*
2023
* build a query string of MC list fields
@@ -23,7 +26,7 @@ const subscribeEmailToMailchimp = url => new Promise((resolve, reject) => jsonp(
2326
* GROUPS: keep as lowercase (ex: MC uses group field names as `group[21269]`)
2427
*/
2528

26-
const convertListFields = (fields) => {
29+
const convertListFields = fields => {
2730
let queryParams = '';
2831
for (const field in fields) {
2932
if (Object.prototype.hasOwnProperty.call(fields, field)) {

yarn.lock

+36
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,13 @@ eslint-config-airbnb-base@^13.1.0:
17511751
object.assign "^4.1.0"
17521752
object.entries "^1.0.4"
17531753

1754+
eslint-config-prettier@^4.2.0:
1755+
version "4.2.0"
1756+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-4.2.0.tgz#70b946b629cd0e3e98233fd9ecde4cb9778de96c"
1757+
integrity sha512-y0uWc/FRfrHhpPZCYflWC8aE0KRJRY04rdZVfl8cL3sEZmOYyaBdhdlQPjKZBnuRMyLVK+JUZr7HaZFClQiH4w==
1758+
dependencies:
1759+
get-stdin "^6.0.0"
1760+
17541761
eslint-import-resolver-node@^0.3.2:
17551762
version "0.3.2"
17561763
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz#58f15fb839b8d0576ca980413476aab2472db66a"
@@ -1784,6 +1791,13 @@ eslint-plugin-import@^2.17.2:
17841791
read-pkg-up "^2.0.0"
17851792
resolve "^1.10.0"
17861793

1794+
eslint-plugin-prettier@^3.0.1:
1795+
version "3.0.1"
1796+
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.1.tgz#19d521e3981f69dd6d14f64aec8c6a6ac6eb0b0d"
1797+
integrity sha512-/PMttrarPAY78PLvV3xfWibMOdMDl57hmlQ2XqFeA37wd+CJ7WSxV7txqjVPHi/AAFKd2lX0ZqfsOc/i5yFCSQ==
1798+
dependencies:
1799+
prettier-linter-helpers "^1.0.0"
1800+
17871801
eslint-plugin-react@^7.12.4:
17881802
version "7.12.4"
17891803
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.12.4.tgz#b1ecf26479d61aee650da612e425c53a99f48c8c"
@@ -2017,6 +2031,11 @@ fast-deep-equal@^2.0.1:
20172031
version "2.0.1"
20182032
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
20192033

2034+
fast-diff@^1.1.2:
2035+
version "1.2.0"
2036+
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
2037+
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
2038+
20202039
fast-json-stable-stringify@^2.0.0:
20212040
version "2.0.0"
20222041
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
@@ -2253,6 +2272,11 @@ get-own-enumerable-property-symbols@^3.0.0:
22532272
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.0.tgz#b877b49a5c16aefac3655f2ed2ea5b684df8d203"
22542273
integrity sha512-CIJYJC4GGF06TakLg8z4GQKvDsx9EMspVxOYih7LerEL/WosUnFIww45CGfxfeKHqlg3twgUrYRT1O3WQqjGCg==
22552274

2275+
get-stdin@^6.0.0:
2276+
version "6.0.0"
2277+
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
2278+
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
2279+
22562280
get-stdin@^7.0.0:
22572281
version "7.0.0"
22582282
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-7.0.0.tgz#8d5de98f15171a125c5e516643c7a6d0ea8a96f6"
@@ -3838,6 +3862,18 @@ preserve@^0.2.0:
38383862
version "0.2.0"
38393863
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
38403864

3865+
prettier-linter-helpers@^1.0.0:
3866+
version "1.0.0"
3867+
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
3868+
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
3869+
dependencies:
3870+
fast-diff "^1.1.2"
3871+
3872+
prettier@^1.17.0:
3873+
version "1.17.0"
3874+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008"
3875+
integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==
3876+
38413877
private@^0.1.6, private@^0.1.7:
38423878
version "0.1.8"
38433879
resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff"

0 commit comments

Comments
 (0)