neeto-compliance 1.0.58
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +10 -0
- data/.husky/helpers/verify_neeto_audit.sh +18 -0
- data/.husky/pre-push +7 -0
- data/.neetoci/neetoci.yml +18 -0
- data/.overcommit.yml +47 -0
- data/.rubocop.yml +596 -0
- data/.ruby-version +1 -0
- data/.semaphore/semaphore.yml +33 -0
- data/CHANGELOG.md +375 -0
- data/Gemfile +36 -0
- data/Gemfile.lock +435 -0
- data/README.md +85 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/neeto-audit +11 -0
- data/bin/neeto_repos_verifier/client_config.json +7 -0
- data/bin/neeto_repos_verifier/list_verifier.rb +93 -0
- data/bin/setup +8 -0
- data/bin/sync-neeto-repos +5 -0
- data/bin/sync-with-neeto-commons +5 -0
- data/config/brakeman.ignore +604 -0
- data/data/neeto_repos.json +295 -0
- data/lib/neeto-compliance.rb +21 -0
- data/lib/neeto_compliance/github_access.rb +29 -0
- data/lib/neeto_compliance/neeto_commons.rb +16 -0
- data/lib/neeto_compliance/neeto_repos.rb +59 -0
- data/lib/neeto_compliance/runner.rb +43 -0
- data/lib/neeto_compliance/skippable.rb +19 -0
- data/lib/neeto_compliance/sync_neeto_commons/sync_bin.rb +32 -0
- data/lib/neeto_compliance/sync_neeto_commons/sync_formatters.rb +28 -0
- data/lib/neeto_compliance/sync_neeto_commons/sync_husky.rb +33 -0
- data/lib/neeto_compliance/sync_neeto_commons/sync_misc.rb +36 -0
- data/lib/neeto_compliance/sync_neeto_commons/sync_test_support.rb +38 -0
- data/lib/neeto_compliance/sync_neeto_commons.rb +36 -0
- data/lib/neeto_compliance/verifiers/auto_update_prs_with_latest_master_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/base.rb +77 -0
- data/lib/neeto_compliance/verifiers/bump_version_with_pr_label_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/bundler_version_verifier.rb +48 -0
- data/lib/neeto_compliance/verifiers/circleci_config_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/common_gemfile_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/common_initializers_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/cypress_config_verifier.rb +46 -0
- data/lib/neeto_compliance/verifiers/cypress_plugins_index_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/docker_file_dev_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/environment_config_verifier.rb +38 -0
- data/lib/neeto_compliance/verifiers/gem_version_verifier.rb +33 -0
- data/lib/neeto_compliance/verifiers/gems_verifier_base.rb +44 -0
- data/lib/neeto_compliance/verifiers/gitignore_file_verifier.rb +37 -0
- data/lib/neeto_compliance/verifiers/jsconfig_verifier.rb +187 -0
- data/lib/neeto_compliance/verifiers/neeto_commons_sync_verifier.rb +42 -0
- data/lib/neeto_compliance/verifiers/neeto_gems_version_verifier.rb +36 -0
- data/lib/neeto_compliance/verifiers/newrelic_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/node_version_verifier.rb +84 -0
- data/lib/neeto_compliance/verifiers/package_dependencies_version_verifier.rb +59 -0
- data/lib/neeto_compliance/verifiers/package_json_verifier.rb +46 -0
- data/lib/neeto_compliance/verifiers/roles_verifier.rb +22 -0
- data/lib/neeto_compliance/verifiers/ruby_version_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/semaphoreci_config_verifier.rb +74 -0
- data/lib/neeto_compliance/verifiers/sidekiq_queues_verifier.rb +36 -0
- data/lib/neeto_compliance/verifiers/simplecov_config_verifier.rb +29 -0
- data/lib/neeto_compliance/verifiers/sitemap_config_verifier.rb +29 -0
- data/lib/neeto_compliance/verifiers/slugignore_file_verifier.rb +25 -0
- data/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/bin_files_verifier.rb +29 -0
- data/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/formatter_files_verifier.rb +29 -0
- data/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/husky_files_verifier.rb +29 -0
- data/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/misc_files_verifier.rb +29 -0
- data/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/test_support_files_verifier.rb +28 -0
- data/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier.rb +31 -0
- data/lib/neeto_compliance/verifiers/webpacker_config_verifier.rb +32 -0
- data/lib/neeto_compliance/verifiers_list.rb +55 -0
- data/lib/neeto_compliance/version.rb +5 -0
- data/neeto-compliance.gemspec +35 -0
- data/package.json +9 -0
- data/yarn.lock +8 -0
- metadata +177 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class AutoUpdatePrsWithLatestMasterVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
".github/workflows/auto_update_prs_with_latest_master.yml"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "common_files/github/workflows/auto_update_prs_with_latest_master.yml"
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
require "yaml"
|
6
|
+
require "set"
|
7
|
+
|
8
|
+
module NeetoCompliance
|
9
|
+
class Base
|
10
|
+
def process
|
11
|
+
return true if app_is_exception?
|
12
|
+
|
13
|
+
# preload the path
|
14
|
+
NeetoCompliance::NeetoCommons.path
|
15
|
+
|
16
|
+
success, errors = audit
|
17
|
+
|
18
|
+
unless success
|
19
|
+
errors.each do |error|
|
20
|
+
puts error
|
21
|
+
end
|
22
|
+
else
|
23
|
+
print "[PASS]\n".green
|
24
|
+
end
|
25
|
+
|
26
|
+
success
|
27
|
+
end
|
28
|
+
|
29
|
+
def verifier_name
|
30
|
+
self.class.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def print_description
|
34
|
+
print "%-80s" % [verifier_name]
|
35
|
+
end
|
36
|
+
|
37
|
+
def auto_correct!
|
38
|
+
return true if app_is_exception?
|
39
|
+
|
40
|
+
unless valid?
|
41
|
+
puts autofix_command
|
42
|
+
system autofix_command
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def autofix_suggestion
|
47
|
+
"To fix run: #{autofix_command.yellow}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def error_message
|
51
|
+
"[FAIL]".red
|
52
|
+
end
|
53
|
+
|
54
|
+
def audit
|
55
|
+
print_description
|
56
|
+
errors = []
|
57
|
+
|
58
|
+
unless valid?
|
59
|
+
errors << [error_message, autofix_suggestion, "\n"].join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
[errors.length == 0, errors]
|
63
|
+
end
|
64
|
+
|
65
|
+
def app_is_exception?
|
66
|
+
apps_exception_list.include?(app_name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def app_name
|
70
|
+
@_app_name ||= `git config --get remote.origin.url`.split("/").last.strip.split(".git").first
|
71
|
+
end
|
72
|
+
|
73
|
+
def apps_exception_list
|
74
|
+
[]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class BumpVersionWithPrLabelVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
".github/workflows/bump_version.yml"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "common_files/neeto_gems/github/workflows/bump_version.yml"
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class BundlerVersionVerifier < Base
|
5
|
+
def commons_bundler_version
|
6
|
+
File.read(NeetoCompliance::NeetoCommons.path.join "common_files/.bundler-version").strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_bundler_version
|
10
|
+
`tail -n 1 ./Gemfile.lock`.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def is_same_version_being_used?
|
14
|
+
commons_bundler_version == current_bundler_version
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
unless is_same_version_being_used?
|
19
|
+
@error = %{
|
20
|
+
Please update the bundler version on your machine to #{commons_bundler_version}
|
21
|
+
You can follow the following steps:
|
22
|
+
|
23
|
+
1. Install the latest bundler version:
|
24
|
+
- gem install bundler
|
25
|
+
2. Open Gemfile.lock of the project:
|
26
|
+
- vim ./Gemfile.lock
|
27
|
+
3. Delete the last line that contains the bundler version.
|
28
|
+
4. Run:
|
29
|
+
- bundle install
|
30
|
+
|
31
|
+
You can also watch the following video that contains the same steps:
|
32
|
+
- https://youtu.be/vqAUIQehbKw
|
33
|
+
}
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def autofix_suggestion
|
41
|
+
@error.yellow
|
42
|
+
end
|
43
|
+
|
44
|
+
def autofix_command
|
45
|
+
"gem install bundler; perl -p -i -e 's/#{current_bundler_version}(\n*)\\Z/#{commons_bundler_version}\n/m' Gemfile.lock"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class CircleciConfigVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
".circleci/config.yml"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join local_copy
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class CommonGemfileVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
"Gemfile.common.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "gemfiles", local_copy
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class CommonInitializersVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
"config/initializers/common.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "initializers/common.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class CypressConfigVerifier < Base
|
5
|
+
def cypress_config_files
|
6
|
+
@_cypress_config_files ||= {
|
7
|
+
"cypress-tests/package.json" => NeetoCompliance::NeetoCommons.path.join("cypress/package.json"),
|
8
|
+
"cypress-tests/cypress/jsconfig.json" => NeetoCompliance::NeetoCommons.path.join("cypress/jsconfig.json"),
|
9
|
+
"cypress-tests/cypress/webpack.config.js" => NeetoCompliance::NeetoCommons.path.join("cypress/webpack.config.js"),
|
10
|
+
"cypress-tests/cypress/config/cypress.review.json" => NeetoCompliance::NeetoCommons.path.join("cypress/cypress.review.json"),
|
11
|
+
"cypress-tests/cypress/resolve.js" => NeetoCompliance::NeetoCommons.path.join("cypress/resolve.js")
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def auto_correct!
|
16
|
+
unless valid?
|
17
|
+
@autofix_commands.each do |command|
|
18
|
+
puts command
|
19
|
+
system command
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def autofix_suggestion
|
25
|
+
@autofix_commands.join("\n").yellow
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
@autofix_commands = []
|
30
|
+
|
31
|
+
cypress_config_files.each_pair do |local_file, common_file|
|
32
|
+
unless same_file?(local_file, common_file)
|
33
|
+
@autofix_commands << "cp #{common_file.to_s} #{local_file}"
|
34
|
+
@autofix_commands << "cd cypress-tests && yarn" if local_file == "cypress-tests/package.json"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@autofix_commands.length == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def same_file?(local_file, common_file)
|
42
|
+
File.exist?(local_file) &&
|
43
|
+
`diff #{local_file} #{common_file.to_s}`.empty?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class CypressPluginsIndexVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
"cypress-tests/cypress/plugins/index.js"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "common_files/cypress-tests/cypress/plugins/index.js"
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class DockerFileDevVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
"Dockerfile.dev"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "common_files/Dockerfile.dev"
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff -N #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
`#{verify_command}`.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def autofix_command
|
22
|
+
"cp #{commons_copy} #{local_copy}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class EnvironmentConfigVerifier < Base
|
5
|
+
def environment_configs
|
6
|
+
@_environment_configs ||= {
|
7
|
+
"config/environments/development.rb": "NeetoCommonsBackend::Environments.development(config)",
|
8
|
+
"config/environments/test.rb": "NeetoCommonsBackend::Environments.test(config)",
|
9
|
+
"config/environments/heroku.rb": "NeetoCommonsBackend::Environments.heroku(config)",
|
10
|
+
"config/environments/staging.rb": "NeetoCommonsBackend::Environments.staging(config)",
|
11
|
+
"config/environments/production.rb": "NeetoCommonsBackend::Environments.production(config)",
|
12
|
+
"config/application.rb": "NeetoCommonsBackend::Environments.application(config, self.routes)"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def auto_correct!
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
@errors = []
|
21
|
+
environment_configs.each_pair do |file, command|
|
22
|
+
unless config_missing?(file, command)
|
23
|
+
@errors << "Add #{command} to #{file}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@errors.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def config_missing?(file, command)
|
31
|
+
system("cat #{file} | grep -q '#{command}'")
|
32
|
+
end
|
33
|
+
|
34
|
+
def autofix_suggestion
|
35
|
+
@errors.join("\n").yellow
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class GemVersionVerifier
|
5
|
+
attr_reader :current_version, :latest_version, :gem_name
|
6
|
+
|
7
|
+
def initialize(current_version, latest_version, gem_name)
|
8
|
+
@latest_version = latest_version
|
9
|
+
@current_version = current_version
|
10
|
+
@gem_name = gem_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def gem_not_installed?
|
14
|
+
current_version.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
def latest_version_installed?
|
18
|
+
current_version == latest_version
|
19
|
+
end
|
20
|
+
|
21
|
+
def equal_app_and_gem_name?
|
22
|
+
app_name == gem_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?
|
26
|
+
equal_app_and_gem_name? || gem_not_installed? || latest_version_installed?
|
27
|
+
end
|
28
|
+
|
29
|
+
def app_name
|
30
|
+
@_app_name ||= `git config --get remote.origin.url`.split("/").last.strip.split(".git").first
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class GemsVerifierBase < Base
|
5
|
+
def gems
|
6
|
+
[]
|
7
|
+
end
|
8
|
+
|
9
|
+
def latest_versions
|
10
|
+
@_latest_versions ||= _latest_versions
|
11
|
+
end
|
12
|
+
|
13
|
+
def _latest_versions
|
14
|
+
JSON.parse(Net::HTTP.get_response(URI("https://neeto-library-stable-versions.herokuapp.com/versions")).body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
@failed_gems = []
|
19
|
+
load_current_versions
|
20
|
+
gems.map do |gem|
|
21
|
+
gv = GemVersionVerifier.new(@current_versions[gem[:name]], find_latest_version(gem[:name]), gem[:name])
|
22
|
+
unless gv.valid?
|
23
|
+
@failed_gems << gem[:name]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@failed_gems.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def autofix_command
|
31
|
+
"bundle update #{@failed_gems.join(' ')}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_current_versions
|
35
|
+
@current_versions = {}
|
36
|
+
Bundler.load.specs.each { |gem| @current_versions[gem.name] = gem.version.to_s }
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_latest_version(gem_name)
|
40
|
+
gem = latest_versions.find { |gem| gem["name"] == gem_name } || {}
|
41
|
+
gem["released_version"]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NeetoCompliance
|
4
|
+
class GitignoreFileVerifier < Base
|
5
|
+
def local_copy
|
6
|
+
".gitignore"
|
7
|
+
end
|
8
|
+
|
9
|
+
def commons_copy
|
10
|
+
NeetoCompliance::NeetoCommons.path.join "common_files", local_copy
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_command
|
14
|
+
"diff #{commons_copy} #{local_copy}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
@missing_lines = []
|
19
|
+
local_gitignore = process_data File.read(local_copy)
|
20
|
+
common_gitignore = process_data File.read(NeetoCompliance::GitignoreFileVerifier.new.commons_copy)
|
21
|
+
common_gitignore.map { |line| @missing_lines << line unless local_gitignore.include?(line) }
|
22
|
+
@missing_lines.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def process_data(gitignore_data)
|
26
|
+
gitignore_data.split("\n").map { |line| line.gsub(/^#.*/, "") }
|
27
|
+
end
|
28
|
+
|
29
|
+
def autofix_command
|
30
|
+
"echo '#{@missing_lines.join("\n")}' >> #{local_copy}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def autofix_suggestion
|
34
|
+
"Add following lines to#{local_copy}: \n#{@missing_lines.join("\n")}".yellow
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hashdiff"
|
4
|
+
|
5
|
+
module NeetoCompliance
|
6
|
+
class JsconfigVerifier < Base
|
7
|
+
attr_accessor :diffs
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@diffs = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def local_copy
|
14
|
+
"app/javascript/jsconfig.json"
|
15
|
+
end
|
16
|
+
|
17
|
+
def commons_copy
|
18
|
+
NeetoCompliance::NeetoCommons.path.join "common_files", "app", "javascript", "jsconfig.json"
|
19
|
+
end
|
20
|
+
|
21
|
+
def local_jsconfig
|
22
|
+
@_local_jsconfig ||= read_file local_copy
|
23
|
+
end
|
24
|
+
|
25
|
+
def required_jsconfig
|
26
|
+
@_required_jsconfig ||= read_file commons_copy
|
27
|
+
end
|
28
|
+
|
29
|
+
def read_file(file)
|
30
|
+
JSON.parse File.read(file)
|
31
|
+
end
|
32
|
+
|
33
|
+
def verify_command
|
34
|
+
self.diffs = Hashdiff.best_diff(required_jsconfig, local_jsconfig)
|
35
|
+
# diffs is an array of differences and each element is a diff.
|
36
|
+
|
37
|
+
self.diffs.any? { |diff| removed_or_modified?(diff) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def removed_or_modified?(diff)
|
41
|
+
# A diff is of the format: ['-', 'a.x', 2]
|
42
|
+
# A modified key is of the format: ['~', 'a.x', 2, 4]
|
43
|
+
# First element is a symbol. '-' indicates removal and `~` indicates modification
|
44
|
+
|
45
|
+
diff[0] == "-" || diff[0] == "~"
|
46
|
+
end
|
47
|
+
|
48
|
+
def local_file_exists?
|
49
|
+
File.file?(local_copy)
|
50
|
+
end
|
51
|
+
|
52
|
+
def newly_added_paths
|
53
|
+
self.diffs = Hashdiff.diff(required_jsconfig, local_jsconfig, use_lcs: false)
|
54
|
+
capture_addition_into_paths_key = "(?=.*\+)(?=.*compilerOptions.paths)"
|
55
|
+
@_newly_added_paths ||= self.diffs.select { |diff| diff.join =~ /#{capture_addition_into_paths_key}.*/ }
|
56
|
+
end
|
57
|
+
|
58
|
+
def custom_paths
|
59
|
+
paths = Hash.new
|
60
|
+
newly_added_paths.each do |path|
|
61
|
+
if path[0] == "+"
|
62
|
+
key = path[1].split(".").last
|
63
|
+
value = path[2]
|
64
|
+
paths[key] = value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@_custom_paths ||= paths
|
68
|
+
end
|
69
|
+
|
70
|
+
def modified_paths
|
71
|
+
paths = Hash.new
|
72
|
+
newly_added_paths.each do |path|
|
73
|
+
if path[0] == "~"
|
74
|
+
# An unwanted '[0]' character is added at the to all modified diffs by the gem
|
75
|
+
|
76
|
+
paths[path[1].split(".").last.chomp("[0]")] = { common: path[2], local: path[3] }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@_modified_paths ||= paths
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_comments_to_jsconfig_file
|
83
|
+
text = File.read(local_copy)
|
84
|
+
text['"commons_paths_comment": "",'] = "// don't modify the below paths without consulting with neetoCompliance team"
|
85
|
+
text['"custom_paths_comment": ""'] = "// You can add custom project specific paths below this comment"
|
86
|
+
File.open(local_copy, "w") { |file| file.puts text }
|
87
|
+
end
|
88
|
+
|
89
|
+
def exception_message(paths)
|
90
|
+
modified_paths = ""
|
91
|
+
paths.each do |key, value|
|
92
|
+
modified_paths += "
|
93
|
+
path: #{key}
|
94
|
+
Common value: [\"#{value[:common]}\"]
|
95
|
+
Project's value: [\"#{value[:local]}\"]"
|
96
|
+
end
|
97
|
+
exception_message = %{
|
98
|
+
Could not autofix jsconfig changes. The below path(s) conflict with the one defined in neeto-commons-backend: #{modified_paths}
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def add_place_holders_for_comments
|
103
|
+
# Adds placeholders into the entire object to keep track of places where we need to insert comments
|
104
|
+
|
105
|
+
paths_with_comment =
|
106
|
+
{ "commons_paths_comment": "" }.merge(required_jsconfig["compilerOptions"]["paths"])
|
107
|
+
paths_with_comment = paths_with_comment.merge("custom_paths_comment": "")
|
108
|
+
paths_with_comment.merge(custom_paths)
|
109
|
+
end
|
110
|
+
|
111
|
+
def write_jsconfig_object_to_file
|
112
|
+
jsconfig_data = required_jsconfig
|
113
|
+
jsconfig_data["compilerOptions"]["paths"] = add_place_holders_for_comments
|
114
|
+
File.open(local_copy, "w") do |file|
|
115
|
+
file.write(JSON.pretty_generate(jsconfig_data))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def auto_correct!
|
120
|
+
unless valid?
|
121
|
+
if !modified_paths.empty?
|
122
|
+
raise StandardError.new exception_message(modified_paths)
|
123
|
+
end
|
124
|
+
|
125
|
+
write_jsconfig_object_to_file
|
126
|
+
add_comments_to_jsconfig_file
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def valid?
|
131
|
+
return false unless local_file_exists?
|
132
|
+
|
133
|
+
is_modified_or_removed = verify_command
|
134
|
+
!is_modified_or_removed
|
135
|
+
end
|
136
|
+
|
137
|
+
def autofix_command
|
138
|
+
"cp #{commons_copy} #{local_copy}"
|
139
|
+
end
|
140
|
+
|
141
|
+
def neeto_audit_script_command
|
142
|
+
"bundle exec neeto-audit -a"
|
143
|
+
end
|
144
|
+
|
145
|
+
def upstream_copy
|
146
|
+
"https://github.com/bigbinary/neeto-commons-backend/blob/stable/lib/neeto-commons-backend/common_files/app/javascript/jsconfig.json"
|
147
|
+
end
|
148
|
+
|
149
|
+
def autofix_suggestion
|
150
|
+
base_message = %{
|
151
|
+
Your jsconfig.json content doesn't match with the expected neeto-commons content.
|
152
|
+
|
153
|
+
The following is the recommended jsconfig.json content in neeto ecosystem:
|
154
|
+
1) View #{upstream_copy}
|
155
|
+
2) Or open #{commons_copy}
|
156
|
+
|
157
|
+
This can be fixed automatically by running:
|
158
|
+
#{neeto_audit_script_command.yellow}
|
159
|
+
|
160
|
+
To fix manually, start by fully replacing app/javascript/jsconfig.json
|
161
|
+
of your app with above mentioned content, by running the following:
|
162
|
+
#{autofix_command.yellow}
|
163
|
+
}
|
164
|
+
|
165
|
+
# The following is an example diff:
|
166
|
+
# [["-", "compilerOptions.moduleResolution", "NodeNext"],
|
167
|
+
# ["~", "compilerOptions.module", "ESNext", "ESNex"],
|
168
|
+
# ["+", "compilerOptions.paths.neetou", ["../../node_modules/@bigbinary/neetoui/**"]],
|
169
|
+
# For the above diff, we only need to get the newly added items marked by "+"
|
170
|
+
# and also check whether it's a "path" that has been added.
|
171
|
+
if newly_added_paths.empty?
|
172
|
+
return base_message
|
173
|
+
end
|
174
|
+
|
175
|
+
message = %{
|
176
|
+
#{base_message}
|
177
|
+
==================================================
|
178
|
+
It seems that you've also added some custom paths in your jsconfig. You can cherry pick and
|
179
|
+
append the custom paths to app/javascript/jsconfig.json, if need be, after running above mentioned copy command.
|
180
|
+
Refer the comments in #{upstream_copy}
|
181
|
+
to see how to add custom paths.
|
182
|
+
The following are the custom paths that we have detected in your app/javascript/jsconfig.json:
|
183
|
+
#{JSON.pretty_generate(custom_paths).yellow}
|
184
|
+
}
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|