Skip to content

Commit 05c2324

Browse files
committed
AMP-32165 Adding eslint and prettier, deprecating jshint
1 parent 2723ccd commit 05c2324

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+14506
-11415
lines changed

.eslintrc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
3+
"plugins": ["prettier", "@amplitude/eslint-plugin-amplitude"],
4+
"env": { "es6": true, "browser": true, "node": true },
5+
"parserOptions": {
6+
"sourceType": "module",
7+
"ecmaVersion": 2018
8+
},
9+
"rules": {
10+
"prettier/prettier": "error",
11+
"no-prototype-builtins": "off"
12+
},
13+
"globals": {
14+
"BUILD_COMPAT_REACT_NATIVE": "readonly",
15+
"BUILD_COMPAT_LOCAL_STORAGE": "readonly",
16+
"BUILD_COMPAT_SNIPPET": "readonly",
17+
"BUILD_COMPAT_2_0": "readonly"
18+
}
19+
}

.jshintrc

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

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ build
1414
karma.conf.js
1515
scripts
1616
.npmignore
17-
.jshintrc
17+
.prettierrc.json
18+
.eslintrc.json
1819
amplitude.min.js
1920
amplitude-snippet.min.js
2021
amplitude.nocompat.min.js

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 120,
3+
"proseWrap": "always",
4+
"singleQuote": true,
5+
"trailingComma": "all"
6+
}

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ TESTS = $(wildcard test/*.js)
44
BINS = node_modules/.bin
55
MINIFY = $(BINS)/uglifyjs
66
JSDOC = $(BINS)/jsdoc
7-
JSHINT = $(BINS)/jshint
7+
PRETTIER = $(BINS)/prettier
8+
ESLINT = $(BINS)/eslint
89
BUILD_DIR = build
910
PROJECT = amplitude
1011
OUT = $(PROJECT).js
@@ -65,7 +66,8 @@ README.md: $(SNIPPET_OUT) version
6566
#
6667

6768
$(OUT): node_modules $(SRC) package.json rollup.config.js rollup.min.js rollup.native.js rollup.esm.js rollup.umd.js rollup.umd.min.js
68-
@$(JSHINT) --verbose $(SRC)
69+
@$(PRETTIER) --write $(src)
70+
@$(ESLINT) --fix $(SRC)
6971
@NODE_ENV=production $(ROLLUP) --config rollup.config.js # is the snippet build config
7072
@NODE_ENV=production $(ROLLUP) --config rollup.esm.js # does not concat dependencies, only has module and dependencies
7173
@NODE_ENV=production $(ROLLUP) --config rollup.umd.js # generates npm version, also usable in require js app
@@ -79,7 +81,8 @@ $(OUT): node_modules $(SRC) package.json rollup.config.js rollup.min.js rollup.n
7981
# Target for minified `amplitude-snippet.js` file.
8082
#
8183
$(SNIPPET_OUT): $(SRC) $(SNIPPET)
82-
@$(JSHINT) --verbose $(SNIPPET)
84+
@$(PRETTIER) --write $(src)
85+
@$(ESLINT) --fix $(SRC)
8386
@$(MINIFY) $(SNIPPET) -m -b max-line-len=80,beautify=false | awk 'NF' > $(SNIPPET_OUT)
8487

8588
$(SEGMENT_SNIPPET_OUT): $(SRC) $(SNIPPET)

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"query-string": "5"
2222
},
2323
"devDependencies": {
24+
"@amplitude/eslint-plugin-amplitude": "^1.0.1",
2425
"@babel/core": "^7.3.4",
2526
"@babel/plugin-external-helpers": "^7.2.0",
2627
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
@@ -32,11 +33,13 @@
3233
"@semantic-release/git": "^9.0.0",
3334
"chai": "^4.1.2",
3435
"date-fns": "^1.30.1",
36+
"eslint": "^7.15.0",
37+
"eslint-config-prettier": "^7.0.0",
38+
"eslint-plugin-prettier": "^3.3.0",
3539
"express": "^4.16.2",
3640
"fs-extra": "^4.0.2",
3741
"jsdoc": "^3.6.3",
3842
"jsdoc-to-markdown": "^6.0.1",
39-
"jshint": "^2.9.6",
4043
"karma": "^4.0.0",
4144
"karma-chai": "^0.1.0",
4245
"karma-chrome-launcher": "^2.2.0",
@@ -47,7 +50,7 @@
4750
"karma-sinon": "^1.0.5",
4851
"karma-sourcemap-loader": "^0.3.7",
4952
"mocha": "^4.0.1",
50-
"prettier": "^2.1.1",
53+
"prettier": "^2.2.1",
5154
"requirejs": "^2.3.6",
5255
"rollup": "^1.4.1",
5356
"rollup-plugin-babel": "^4.3.2",
@@ -67,7 +70,13 @@
6770
"docs:install": "cd website/ && yarn install",
6871
"docs:generate-jsdoc": "cd website && yarn generate-jsdoc",
6972
"docs:start": "cd website/ && yarn start",
70-
"docs:deploy": "cd website/ && yarn deploy"
73+
"docs:deploy": "cd website/ && yarn deploy",
74+
"lint": "yarn run lint:prettier && yarn run lint:eslint",
75+
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.js\"",
76+
"lint:eslint": "eslint 'src/**/*.js'",
77+
"fix": "yarn run fix:eslint && yarn run fix:prettier",
78+
"fix:prettier": "prettier --write \"{src,test,scripts}/**/*.js\"",
79+
"fix:eslint": "eslint --fix 'src/**/*.js'"
7180
},
7281
"bugs": {
7382
"url": "https://github.com/amplitude/amplitude-javascript/issues"

scripts/readme.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ var path = require('path');
33

44
// Update the README with the minified snippet.
55
var cwd = process.cwd();
6-
var readmeFilename = path.join(cwd, "README.md");
6+
var readmeFilename = path.join(cwd, 'README.md');
77
var readme = fs.readFileSync(readmeFilename, 'utf-8');
88

9-
var snippetFilename = path.join(cwd, "amplitude-snippet.min.js");
9+
var snippetFilename = path.join(cwd, 'amplitude-snippet.min.js');
1010
var snippet = fs.readFileSync(snippetFilename, 'utf-8');
1111
var script =
12-
' <script type="text/javascript">\n' +
13-
snippet.trim().replace(/^/gm, ' ') + '\n\n' +
14-
' amplitude.getInstance().init("YOUR_API_KEY_HERE");\n' +
15-
' </script>';
12+
' <script type="text/javascript">\n' +
13+
snippet.trim().replace(/^/gm, ' ') +
14+
'\n\n' +
15+
' amplitude.getInstance().init("YOUR_API_KEY_HERE");\n' +
16+
' </script>';
1617

1718
var updated = readme.replace(/ +<script[\s\S]+?script>/, script);
1819
fs.writeFileSync(readmeFilename, updated);

scripts/version.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const {version} = require('../package');
4-
const {format} = require('date-fns');
3+
const { version } = require('../package');
4+
const { format } = require('date-fns');
55
const crypto = require('crypto');
66

77
const cwd = process.cwd();
88

99
function replaceTextInFile(filepath, match, replacement) {
1010
var filename = path.join(cwd, filepath);
1111

12-
const updatedText = fs
13-
.readFileSync(filename, 'utf-8')
14-
.replace(match, replacement);
12+
const updatedText = fs.readFileSync(filename, 'utf-8').replace(match, replacement);
1513

1614
if (updatedText.indexOf(replacement) === -1) {
1715
throw new Error(`Failed to update text in ${filepath}`);

0 commit comments

Comments
 (0)