able_git_hooks 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +117 -0
- data/Gemfile.lock +2 -2
- data/README.md +7 -0
- data/lib/able_git_hooks/generators/install_generator.rb +29 -0
- data/lib/able_git_hooks/generators/templates/_do_hook +1 -1
- data/lib/able_git_hooks/generators/templates/eslint-check.js +76 -0
- data/lib/able_git_hooks/generators/templates/eslintrc.json +33 -0
- data/lib/able_git_hooks/generators/templates/prettierrc +3 -0
- data/lib/able_git_hooks/generators/templates/rubocop.rb +3 -0
- data/lib/able_git_hooks/generators/templates/stylelint-check.js +70 -0
- data/lib/able_git_hooks/generators/templates/stylelintrc +15 -0
- data/lib/able_git_hooks/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c2cfb7a8cf9f20c9239f1fa90bd5b8186be514321d7f9f0fc12ff5fc1786fd4
|
4
|
+
data.tar.gz: fc41fa34ca1a4732b10f70bc3b7a212fedb832dfd03e5c6279742e9775e156ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4012768541ad36d72dba19328eb85ef199f40c38e42e5cd2209e260fc0cfcab3503001d7d46c4ac2372016bb6390312df91ea4ac8245041a10125c9d264029a8
|
7
|
+
data.tar.gz: fd916bca9d07e150bebb6f3029058b629e39c416aeca772f44e0df26b9b9d82e6ce1f7e398c7a9df272a1b1b5156769e28ccab58789fc96b2165a79c3f67d1fd
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
DisabledByDefault: true
|
4
|
+
Exclude:
|
5
|
+
- bin/**/*
|
6
|
+
- node_modules/**/*
|
7
|
+
- db/migrate/*
|
8
|
+
- db/schema.rb
|
9
|
+
TargetRubyVersion: 2.5
|
10
|
+
Layout/AccessModifierIndentation:
|
11
|
+
EnforcedStyle: indent
|
12
|
+
Layout/BlockAlignment:
|
13
|
+
EnforcedStyleAlignWith: either
|
14
|
+
Layout/DefEndAlignment:
|
15
|
+
EnforcedStyleAlignWith: start_of_line
|
16
|
+
Layout/DotPosition:
|
17
|
+
EnforcedStyle: leading
|
18
|
+
Layout/EmptyComment:
|
19
|
+
Enabled: true
|
20
|
+
Layout/EmptyLineBetweenDefs:
|
21
|
+
Enabled: true
|
22
|
+
NumberOfEmptyLines: 1
|
23
|
+
Layout/EmptyLinesAroundBlockBody:
|
24
|
+
EnforcedStyle: no_empty_lines
|
25
|
+
Layout/EmptyLinesAroundClassBody:
|
26
|
+
EnforcedStyle: no_empty_lines
|
27
|
+
Layout/EmptyLinesAroundModuleBody:
|
28
|
+
EnforcedStyle: no_empty_lines
|
29
|
+
Layout/EndAlignment:
|
30
|
+
EnforcedStyleAlignWith: start_of_line
|
31
|
+
Layout/ExtraSpacing:
|
32
|
+
AllowForAlignment: true
|
33
|
+
Layout/IndentArray:
|
34
|
+
EnforcedStyle: consistent
|
35
|
+
Layout/IndentHash:
|
36
|
+
EnforcedStyle: consistent
|
37
|
+
Layout/IndentationConsistency:
|
38
|
+
EnforcedStyle: normal
|
39
|
+
Layout/IndentationWidth:
|
40
|
+
Width: 2
|
41
|
+
Layout/SpaceAroundBlockParameters:
|
42
|
+
EnforcedStyleInsidePipes: no_space
|
43
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
44
|
+
EnforcedStyle: space
|
45
|
+
Layout/SpaceAroundOperators:
|
46
|
+
Enabled: true
|
47
|
+
Layout/SpaceBeforeBlockBraces:
|
48
|
+
EnforcedStyle: space
|
49
|
+
Layout/SpaceInLambdaLiteral:
|
50
|
+
EnforcedStyle: require_no_space
|
51
|
+
Layout/SpaceInsideBlockBraces:
|
52
|
+
EnforcedStyle: space
|
53
|
+
EnforcedStyleForEmptyBraces: no_space
|
54
|
+
Layout/SpaceInsideHashLiteralBraces:
|
55
|
+
EnforcedStyle: space
|
56
|
+
EnforcedStyleForEmptyBraces: no_space
|
57
|
+
Layout/SpaceInsideReferenceBrackets:
|
58
|
+
EnforcedStyle: no_space
|
59
|
+
Layout/SpaceInsideStringInterpolation:
|
60
|
+
EnforcedStyle: no_space
|
61
|
+
Layout/Tab:
|
62
|
+
Enabled: true
|
63
|
+
Layout/TrailingWhitespace:
|
64
|
+
Enabled: true
|
65
|
+
Lint/SafeNavigationChain:
|
66
|
+
Enabled: true
|
67
|
+
Lint/ShadowedArgument:
|
68
|
+
Enabled: true
|
69
|
+
Lint/UnusedBlockArgument:
|
70
|
+
Enabled: true
|
71
|
+
Lint/UnusedMethodArgument:
|
72
|
+
Enabled: true
|
73
|
+
Naming/VariableName:
|
74
|
+
EnforcedStyle: snake_case
|
75
|
+
Rails/LexicallyScopedActionFilter:
|
76
|
+
Include:
|
77
|
+
- app/controllers/**/*.rb
|
78
|
+
Rails/TimeZone:
|
79
|
+
EnforcedStyle: flexible
|
80
|
+
Rails/UnknownEnv:
|
81
|
+
Environments:
|
82
|
+
- development
|
83
|
+
- test
|
84
|
+
- production
|
85
|
+
Style/BlockDelimiters:
|
86
|
+
EnforcedStyle: line_count_based
|
87
|
+
Style/BracesAroundHashParameters:
|
88
|
+
EnforcedStyle: no_braces
|
89
|
+
Style/EmptyElse:
|
90
|
+
EnforcedStyle: both
|
91
|
+
Style/EmptyMethod:
|
92
|
+
EnforcedStyle: expanded
|
93
|
+
Style/HashSyntax:
|
94
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
95
|
+
Style/MethodDefParentheses:
|
96
|
+
EnforcedStyle: require_parentheses
|
97
|
+
Style/NumericLiterals:
|
98
|
+
MinDigits: 5
|
99
|
+
Strict: false
|
100
|
+
Style/RedundantReturn:
|
101
|
+
Enabled: true
|
102
|
+
Style/Semicolon:
|
103
|
+
Enabled: true
|
104
|
+
Style/SingleLineMethods:
|
105
|
+
Enabled: true
|
106
|
+
Style/StabbyLambdaParentheses:
|
107
|
+
EnforcedStyle: require_parentheses
|
108
|
+
Style/StringLiterals:
|
109
|
+
EnforcedStyle: double_quotes
|
110
|
+
Style/StringLiteralsInInterpolation:
|
111
|
+
EnforcedStyle: single_quotes
|
112
|
+
Style/TrailingCommaInArguments:
|
113
|
+
EnforcedStyleForMultiline: no_comma
|
114
|
+
Style/TrailingCommaInArrayLiteral:
|
115
|
+
EnforcedStyleForMultiline: no_comma
|
116
|
+
Style/TrailingCommaInHashLiteral:
|
117
|
+
EnforcedStyleForMultiline: no_comma
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
able_git_hooks (0.
|
4
|
+
able_git_hooks (0.12.0)
|
5
5
|
railties (~> 5.2, >= 5.2.0)
|
6
6
|
rubocop (~> 0.57.2, >= 0.57.2)
|
7
7
|
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
method_source (0.9.0)
|
41
41
|
mini_portile2 (2.3.0)
|
42
42
|
minitest (5.11.3)
|
43
|
-
nokogiri (1.8.
|
43
|
+
nokogiri (1.8.4)
|
44
44
|
mini_portile2 (~> 2.3.0)
|
45
45
|
parallel (1.12.1)
|
46
46
|
parser (2.5.1.0)
|
data/README.md
CHANGED
@@ -24,3 +24,10 @@ And then execute:
|
|
24
24
|
Execute the generator command to copy the files:
|
25
25
|
|
26
26
|
$ bundle exec rails generate able_git_hooks:install
|
27
|
+
|
28
|
+
|
29
|
+
For the ESLint default configuration you'll need to install
|
30
|
+
|
31
|
+
- eslint-plugin-import
|
32
|
+
- eslint-plugin-react
|
33
|
+
- eslint-plugin-prettier
|
@@ -4,6 +4,9 @@ module AbleGitHooks
|
|
4
4
|
desc "Install git hook files"
|
5
5
|
source_root File.expand_path("../templates", __FILE__)
|
6
6
|
|
7
|
+
class_option :with_stylelint, type: :boolean, default: false, description: "Include the default configuration for stylelint"
|
8
|
+
|
9
|
+
|
7
10
|
def install_git_hooks
|
8
11
|
copy_file "_do_hook", ".git/hooks/_do_hook"
|
9
12
|
chmod ".git/hooks/_do_hook", 0755
|
@@ -22,6 +25,32 @@ module AbleGitHooks
|
|
22
25
|
def copy_rubocop_defaults
|
23
26
|
template "rubocop.yml", "config/rubocop.yml"
|
24
27
|
end
|
28
|
+
|
29
|
+
def install_eslint_hooks
|
30
|
+
copy_file "eslint-check.js", "hooks/pre-commit/eslint-check.js"
|
31
|
+
chmod "hooks/pre-commit/eslint-check.js", 0755
|
32
|
+
end
|
33
|
+
|
34
|
+
def copy_eslint_defaults
|
35
|
+
copy_file "eslintrc.json", ".eslintrc.json"
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy_prettier_defaults
|
39
|
+
copy_file "prettierrc", ".prettierrc"
|
40
|
+
end
|
41
|
+
|
42
|
+
def install_stylelint_hooks
|
43
|
+
if options["with_stylelint"]
|
44
|
+
copy_file "stylelint-check.js", "hooks/pre-commit/stylelint-check.js"
|
45
|
+
chmod "hooks/pre-commit/stylelint-check.js", 0755
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def copy_stylelint_defaults
|
50
|
+
if options["with_stylelint"]
|
51
|
+
copy_file "stylelintrc", ".stylelintrc"
|
52
|
+
end
|
53
|
+
end
|
25
54
|
end
|
26
55
|
end
|
27
56
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
"use strict";
|
4
|
+
|
5
|
+
/***
|
6
|
+
* Description:
|
7
|
+
* Run prettier on the files are they are staged to be commit. Exit successfully
|
8
|
+
* only if the file would be left unchanged by prettier.
|
9
|
+
*
|
10
|
+
* Steps:
|
11
|
+
*
|
12
|
+
* 1. List the sources files that are to be committed.
|
13
|
+
* 2. Use git show :<path> to print the staged file to stdout.
|
14
|
+
* 3. Pipe stdout to `prettier.check`.
|
15
|
+
*
|
16
|
+
***/
|
17
|
+
|
18
|
+
const { promisify } = require("util");
|
19
|
+
let { exec } = require("child_process");
|
20
|
+
exec = promisify(exec);
|
21
|
+
const ESLintCLIEngine = require("eslint").CLIEngine;
|
22
|
+
const cli = new ESLintCLIEngine({});
|
23
|
+
const formatter = cli.getFormatter();
|
24
|
+
|
25
|
+
|
26
|
+
const getStagedFiles =
|
27
|
+
"git diff --staged --name-only -z --diff-filter=ACMR";
|
28
|
+
|
29
|
+
const onlyJSFiles = filenames => {
|
30
|
+
return filenames.filter(
|
31
|
+
file => file.endsWith(".js") || file.endsWith(".jsx"),
|
32
|
+
);
|
33
|
+
};
|
34
|
+
|
35
|
+
const splitFileNames = ret => {
|
36
|
+
const fileNames = ret.stdout.substring(0, ret.stdout.length - 1);
|
37
|
+
return fileNames.split("\u0000");
|
38
|
+
};
|
39
|
+
|
40
|
+
function and(x, y) {
|
41
|
+
return x && y;
|
42
|
+
}
|
43
|
+
|
44
|
+
const reduceWithAnd = xs => {
|
45
|
+
return xs.reduce(and, true);
|
46
|
+
};
|
47
|
+
|
48
|
+
const exit = success => {
|
49
|
+
if (success) {
|
50
|
+
process.exit(0);
|
51
|
+
} else {
|
52
|
+
process.exit(1);
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
function lintFile(filepath) {
|
57
|
+
return exec(`git show :${filepath}`).then(ret => {
|
58
|
+
const report = cli.executeOnText(ret.stdout, filepath);
|
59
|
+
if (report.errorCount > 0 || report.warningCount > 0) {
|
60
|
+
const errorResults = ESLintCLIEngine.getErrorResults(report.results);
|
61
|
+
console.log(formatter(errorResults));
|
62
|
+
}
|
63
|
+
return report.errorCount === 0 && report.warningCount === 0;
|
64
|
+
});
|
65
|
+
}
|
66
|
+
|
67
|
+
function lintFiles(filepaths) {
|
68
|
+
return Promise.all(filepaths.map(lintFile));
|
69
|
+
}
|
70
|
+
|
71
|
+
exec(getStagedFiles)
|
72
|
+
.then(splitFileNames)
|
73
|
+
.then(onlyJSFiles)
|
74
|
+
.then(lintFiles)
|
75
|
+
.then(reduceWithAnd)
|
76
|
+
.then(exit);
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"parserOptions": {
|
3
|
+
"ecmaVersion": 6,
|
4
|
+
"sourceType": "module",
|
5
|
+
"ecmaFeatures": {
|
6
|
+
"jsx": true
|
7
|
+
}
|
8
|
+
},
|
9
|
+
plugins: ["import", "react", "prettier"],
|
10
|
+
"rules": {
|
11
|
+
"no-dupe-keys": "error",
|
12
|
+
"no-undef": "error",
|
13
|
+
"no-unreachable": "error",
|
14
|
+
"no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
15
|
+
"no-useless-constructor": "error",
|
16
|
+
"no-var": "error",
|
17
|
+
"no-duplicate-imports": "error",
|
18
|
+
"no-duplicate-case": "error",
|
19
|
+
"no-console": "error",
|
20
|
+
"no-debugger": "error",
|
21
|
+
"import/no-unresolved": "error",
|
22
|
+
"import/default": "error",
|
23
|
+
"react/jsx-no-undef": "error",
|
24
|
+
"react/jsx-uses-vars": 1,
|
25
|
+
"react/jsx-uses-react": "error",
|
26
|
+
"react/react-in-jsx-scope": "error",
|
27
|
+
"react/no-string-refs": "error",
|
28
|
+
"react/prop-types": ["error", { skipUndeclared: true }],
|
29
|
+
"react/forbid-prop-types": "error",
|
30
|
+
"react/prefer-stateless-function": "error",
|
31
|
+
"prettier/prettier": "error"
|
32
|
+
}
|
33
|
+
}
|
@@ -4,6 +4,9 @@ require "rubocop"
|
|
4
4
|
require "shellwords"
|
5
5
|
|
6
6
|
staged_files = `git diff -z --staged --name-only --diff-filter=ACM`.split("\u0000")
|
7
|
+
|
8
|
+
exit 0 if staged_files.empty?
|
9
|
+
|
7
10
|
config_store = RuboCop::ConfigStore.new
|
8
11
|
target_files = RuboCop::TargetFinder.new(config_store).find(staged_files)
|
9
12
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
'use strict';
|
4
|
+
|
5
|
+
/***
|
6
|
+
* Description:
|
7
|
+
* Run stylelint against the staged version of style files. If any errors are
|
8
|
+
* found by stylelint, print them to standard output and return with a non-zero
|
9
|
+
* exit code. Otherwise return successfully.
|
10
|
+
***/
|
11
|
+
|
12
|
+
const { promisify } = require('util');
|
13
|
+
let { exec } = require('child_process');
|
14
|
+
exec = promisify(exec);
|
15
|
+
const stylelint = require('stylelint');
|
16
|
+
|
17
|
+
|
18
|
+
const getStagedFiles =
|
19
|
+
"git diff --staged --name-only -z --diff-filter=ACMR";
|
20
|
+
|
21
|
+
const onlyJSFiles = filenames => {
|
22
|
+
return filenames.filter(
|
23
|
+
file => file.endsWith(".js") || file.endsWith(".jsx"),
|
24
|
+
);
|
25
|
+
};
|
26
|
+
|
27
|
+
const splitFileNames = ret => {
|
28
|
+
const fileNames = ret.stdout.substring(0, ret.stdout.length - 1);
|
29
|
+
return fileNames.split("\u0000");
|
30
|
+
};
|
31
|
+
|
32
|
+
function and(x, y) {
|
33
|
+
return x && y;
|
34
|
+
}
|
35
|
+
|
36
|
+
const reduceWithAnd = xs => {
|
37
|
+
return xs.reduce(and, true);
|
38
|
+
};
|
39
|
+
|
40
|
+
const exit = success => {
|
41
|
+
if (success) {
|
42
|
+
process.exit(0);
|
43
|
+
} else {
|
44
|
+
process.exit(1);
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
function lintFile(filepath) {
|
49
|
+
return exec(`git show :${filepath}`)
|
50
|
+
.then(ret => stylelint.lint({ code: ret.stdout, codeFilename: filepath, formatter: 'verbose' }))
|
51
|
+
.then(result => {
|
52
|
+
if (!result.errored) {
|
53
|
+
return true;
|
54
|
+
} else {
|
55
|
+
console.log(result.output);
|
56
|
+
return false;
|
57
|
+
}
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
function lintFiles(filepaths) {
|
62
|
+
return Promise.all(filepaths.map(lintFile));
|
63
|
+
}
|
64
|
+
|
65
|
+
exec(getStagedFiles)
|
66
|
+
.then(splitFileNames)
|
67
|
+
.then(onlyStyleFiles)
|
68
|
+
.then(lintFiles)
|
69
|
+
.then(reduceWithAnd)
|
70
|
+
.then(exit);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"processors": ["stylelint-processor-styled-components"],
|
3
|
+
"extends": [
|
4
|
+
"stylelint-config-standard",
|
5
|
+
"stylelint-config-styled-components"
|
6
|
+
],
|
7
|
+
"syntax": "scss",
|
8
|
+
"plugins": ["stylelint-order"],
|
9
|
+
"rules": {
|
10
|
+
"order/properties-alphabetical-order": true,
|
11
|
+
"block-opening-brace-space-after": null,
|
12
|
+
"block-closing-brace-space-before": null,
|
13
|
+
"color-hex-case": "lower"
|
14
|
+
}
|
15
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: able_git_hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Rodas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-07-
|
12
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
105
106
|
- Gemfile
|
106
107
|
- Gemfile.lock
|
107
108
|
- LICENSE.txt
|
@@ -113,8 +114,13 @@ files:
|
|
113
114
|
- lib/able_git_hooks.rb
|
114
115
|
- lib/able_git_hooks/generators/install_generator.rb
|
115
116
|
- lib/able_git_hooks/generators/templates/_do_hook
|
117
|
+
- lib/able_git_hooks/generators/templates/eslint-check.js
|
118
|
+
- lib/able_git_hooks/generators/templates/eslintrc.json
|
119
|
+
- lib/able_git_hooks/generators/templates/prettierrc
|
116
120
|
- lib/able_git_hooks/generators/templates/rubocop.rb
|
117
121
|
- lib/able_git_hooks/generators/templates/rubocop.yml
|
122
|
+
- lib/able_git_hooks/generators/templates/stylelint-check.js
|
123
|
+
- lib/able_git_hooks/generators/templates/stylelintrc
|
118
124
|
- lib/able_git_hooks/railtie.rb
|
119
125
|
- lib/able_git_hooks/version.rb
|
120
126
|
homepage: http://able.co
|
@@ -137,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
143
|
version: '0'
|
138
144
|
requirements: []
|
139
145
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.7.
|
146
|
+
rubygems_version: 2.7.7
|
141
147
|
signing_key:
|
142
148
|
specification_version: 4
|
143
149
|
summary: Creates an extensible git hooks system on rails projects
|