Skip to content

Commit 1f61f21

Browse files
committed
chore: configure prettier and eslint
- add prettier to do formatting - add eslint-config-prettier to disable rules conflicting with prettier - remove eslint from grunt workflow - use lint-stage to lint and format on precommit - use eslint and prettier in travis directly - remove rules that are already part of the "recommended" ruleset That rational is that eslint and prettier should be run in Travis-CI, on commit and as IDE integration (highlighting errors directlry). They don't need to be run along with test-cases. Getting linting errors when running the tests because of missing semicolons is just annoying, but doesn't help the overall code-quality.
1 parent 587e7a3 commit 1f61f21

19 files changed

+1890
-553
lines changed

.eslintignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.rvmrc
2+
.DS_Store
3+
/tmp/
4+
*.sublime-project
5+
*.sublime-workspace
6+
npm-debug.log
7+
sauce_connect.log*
8+
.idea
9+
yarn-error.log
10+
node_modules
11+
/handlebars-release.tgz
12+
13+
# Generated files
14+
lib/handlebars/compiler/parser.js
15+
/coverage/
16+
/dist/
17+
/integration-testing/*/dist/
18+
19+
# Third-party or files that must remain unchanged
20+
/spec/expected/
21+
/spec/vendor
22+
23+
# JS-Snippets
24+
src/*.js

.eslintrc.js

+51-102
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,67 @@
11
module.exports = {
2-
"extends": ["eslint:recommended","plugin:compat/recommended"],
3-
"globals": {
4-
"self": false
2+
extends: ['eslint:recommended', 'plugin:compat/recommended', 'prettier'],
3+
globals: {
4+
self: false
55
},
6-
"env": {
7-
"node": true,
8-
"es6": true
6+
env: {
7+
node: true,
8+
es6: true
99
},
10-
"rules": {
11-
// overrides eslint:recommended defaults
12-
"no-sparse-arrays": "off",
13-
"no-func-assign": "off",
14-
"no-console": "warn",
15-
"no-debugger": "warn",
16-
"no-unreachable": "warn",
17-
18-
// Possible Errors //
19-
//-----------------//
20-
"no-unsafe-negation": "error",
10+
rules: {
11+
'no-console': 'warn',
2112

13+
// temporarily disabled until the violating places are fixed.
14+
'no-func-assign': 'off',
15+
'no-sparse-arrays': 'off',
2216

2317
// Best Practices //
2418
//----------------//
25-
"curly": "error",
26-
"default-case": "warn",
27-
"dot-notation": ["error", { "allowKeywords": false }],
28-
"guard-for-in": "warn",
29-
"no-alert": "error",
30-
"no-caller": "error",
31-
"no-div-regex": "warn",
32-
"no-eval": "error",
33-
"no-extend-native": "error",
34-
"no-extra-bind": "error",
35-
"no-floating-decimal": "error",
36-
"no-implied-eval": "error",
37-
"no-iterator": "error",
38-
"no-labels": "error",
39-
"no-lone-blocks": "error",
40-
"no-loop-func": "error",
41-
"no-multi-spaces": "error",
42-
"no-multi-str": "warn",
43-
"no-global-assign": "error",
44-
"no-new": "error",
45-
"no-new-func": "error",
46-
"no-new-wrappers": "error",
47-
"no-octal-escape": "error",
48-
"no-process-env": "error",
49-
"no-proto": "error",
50-
"no-return-assign": "error",
51-
"no-script-url": "error",
52-
"no-self-compare": "error",
53-
"no-sequences": "error",
54-
"no-throw-literal": "error",
55-
"no-unused-expressions": "error",
56-
"no-warning-comments": "warn",
57-
"no-with": "error",
58-
"radix": "error",
59-
"wrap-iife": "error",
60-
"no-prototype-builtins": "error",
61-
19+
'default-case': 'warn',
20+
'dot-notation': ['error', { allowKeywords: false }],
21+
'guard-for-in': 'warn',
22+
'no-alert': 'error',
23+
'no-caller': 'error',
24+
'no-div-regex': 'warn',
25+
'no-eval': 'error',
26+
'no-extend-native': 'error',
27+
'no-extra-bind': 'error',
28+
'no-floating-decimal': 'error',
29+
'no-implied-eval': 'error',
30+
'no-iterator': 'error',
31+
'no-labels': 'error',
32+
'no-lone-blocks': 'error',
33+
'no-loop-func': 'error',
34+
'no-multi-str': 'warn',
35+
'no-global-assign': 'error',
36+
'no-new': 'error',
37+
'no-new-func': 'error',
38+
'no-new-wrappers': 'error',
39+
'no-octal-escape': 'error',
40+
'no-process-env': 'error',
41+
'no-proto': 'error',
42+
'no-return-assign': 'error',
43+
'no-script-url': 'error',
44+
'no-self-compare': 'error',
45+
'no-sequences': 'error',
46+
'no-throw-literal': 'error',
47+
'no-unused-expressions': 'error',
48+
'no-warning-comments': 'warn',
49+
'no-with': 'error',
50+
radix: 'error',
6251

6352
// Variables //
6453
//-----------//
65-
"no-catch-shadow": "error",
66-
"no-label-var": "error",
67-
"no-shadow-restricted-names": "error",
68-
"no-undef-init": "error",
69-
"no-use-before-define": ["error", "nofunc"],
70-
71-
72-
// Stylistic Issues //
73-
//------------------//
74-
"comma-dangle": ["error", "never"],
75-
"quote-props": ["error", "as-needed", { "keywords": true, "unnecessary": false }],
76-
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
77-
"camelcase": "error",
78-
"comma-spacing": ["error", { "before": false, "after": true }],
79-
"comma-style": ["error", "last"],
80-
"consistent-this": ["warn", "self"],
81-
"eol-last": "error",
82-
"func-style": ["error", "declaration"],
83-
"key-spacing": ["error", {
84-
"beforeColon": false,
85-
"afterColon": true
86-
}],
87-
"new-cap": "error",
88-
"new-parens": "error",
89-
"no-array-constructor": "error",
90-
"no-lonely-if": "error",
91-
"no-mixed-spaces-and-tabs": "error",
92-
"no-nested-ternary": "warn",
93-
"no-new-object": "error",
94-
"no-spaced-func": "error",
95-
"no-trailing-spaces": "error",
96-
"no-extra-parens": ["error", "functions"],
97-
"quotes": ["error", "single", "avoid-escape"],
98-
"semi": "error",
99-
"semi-spacing": ["error", { "before": false, "after": true }],
100-
"keyword-spacing": "error",
101-
"space-before-blocks": ["error", "always"],
102-
"space-before-function-paren": ["error", { "anonymous": "never", "named": "never" }],
103-
"space-in-parens": ["error", "never"],
104-
"space-infix-ops": "error",
105-
"space-unary-ops": "error",
106-
"spaced-comment": ["error", "always", { "markers": [","] }],
107-
"wrap-regex": "warn",
54+
'no-label-var': 'error',
55+
'no-undef-init': 'error',
56+
'no-use-before-define': ['error', 'nofunc'],
10857

10958
// ECMAScript 6 //
11059
//--------------//
111-
"no-var": "warn"
60+
'no-var': 'error'
11261
},
113-
"parserOptions": {
114-
"sourceType": "module",
115-
"ecmaVersion": 6,
116-
"ecmaFeatures": {}
62+
parserOptions: {
63+
sourceType: 'module',
64+
ecmaVersion: 6,
65+
ecmaFeatures: {}
11766
}
11867
};

.gitignore

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
vendor
21
.rvmrc
32
.DS_Store
4-
lib/handlebars/compiler/parser.js
5-
/dist/
63
/tmp/
7-
/coverage/
8-
node_modules
94
*.sublime-project
105
*.sublime-workspace
116
npm-debug.log
127
sauce_connect.log*
138
.idea
14-
yarn-error.log
9+
/yarn-error.log
10+
/yarn.lock
11+
node_modules
1512
/handlebars-release.tgz
13+
14+
# Generated files
15+
lib/handlebars/compiler/parser.js
16+
/coverage/
17+
/dist/
18+
/integration-testing/*/dist/

.prettierignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.rvmrc
2+
.DS_Store
3+
/tmp/
4+
*.sublime-project
5+
*.sublime-workspace
6+
npm-debug.log
7+
sauce_connect.log*
8+
.idea
9+
yarn-error.log
10+
node_modules
11+
/handlebars-release.tgz
12+
13+
# Generated files
14+
lib/handlebars/compiler/parser.js
15+
/coverage/
16+
/dist/
17+
/integration-testing/*/dist/
18+
19+
# Third-party or files that must remain unchanged
20+
/spec/expected/
21+
/spec/vendor

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: node_js
22
before_install:
33
- npm install -g grunt-cli
44
script:
5+
- npm run lint
6+
- npm run check-format
57
- grunt --stack travis
68
email:
79
on_failure: change

Gruntfile.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ module.exports = function(grunt) {
44
grunt.initConfig({
55
pkg: grunt.file.readJSON('package.json'),
66

7-
eslint: {
8-
files: [
9-
'*.js',
10-
'bench/**/*.js',
11-
'tasks/**/*.js',
12-
'lib/**/!(*.min|parser).js',
13-
'spec/**/!(*.amd|json2|require).js',
14-
'integration-testing/multi-nodejs-test/*.js',
15-
'integration-testing/webpack-test/*.js',
16-
'integration-testing/webpack-test/src/*.js'
17-
]
18-
},
19-
207
clean: ['tmp', 'dist', 'lib/handlebars/compiler/parser.js', 'integration-testing/**/node_modules'],
218

229
copy: {
@@ -215,7 +202,6 @@ module.exports = function(grunt) {
215202

216203
// Build a new version of the library
217204
this.registerTask('build', 'Builds a distributable version of the current project', [
218-
'eslint',
219205
'bgShell:checkTypes',
220206
'parser',
221207
'node',
@@ -226,7 +212,7 @@ module.exports = function(grunt) {
226212
this.registerTask('globals', ['webpack']);
227213
this.registerTask('tests', ['concat:tests']);
228214

229-
this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'uglify', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']);
215+
this.registerTask('release', 'Build final packages', ['amd', 'uglify', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']);
230216

231217
// Load tasks from npm
232218
grunt.loadNpmTasks('grunt-contrib-clean');
@@ -238,7 +224,6 @@ module.exports = function(grunt) {
238224
grunt.loadNpmTasks('grunt-contrib-watch');
239225
grunt.loadNpmTasks('grunt-babel');
240226
grunt.loadNpmTasks('grunt-bg-shell');
241-
grunt.loadNpmTasks('grunt-eslint');
242227
grunt.loadNpmTasks('@knappi/grunt-saucelabs');
243228
grunt.loadNpmTasks('grunt-webpack');
244229

bench/.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"extends": "prettier",
23
"globals": {
34
"require": true
45
},
@@ -11,4 +12,4 @@
1112
"handle-callback-err": 0,
1213
"no-console": 0
1314
}
14-
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module.exports = {
2-
"extends": "eslint:recommended",
3-
"globals": {
4-
"self": false
2+
extends: ['eslint:recommended', 'plugin:es5/no-es2015', 'prettier'],
3+
globals: {
4+
self: false
55
},
6-
"env": {
7-
"node": true
6+
env: {
7+
node: true
88
},
9-
"rules": {
10-
'no-console': 'off'
9+
rules: {
10+
'no-console': 'off',
11+
'no-var': 'off'
1112
}
12-
}
13+
};

0 commit comments

Comments
 (0)