ndr_dev_support 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65678f389d477156798555985f5dadffa993f72e
4
+ data.tar.gz: 488e28b29645423774120f1dd44a8a7b0577c5c4
5
+ SHA512:
6
+ metadata.gz: 8d1d94e0acdea556a5bf333a2980da539da83f617749aa41c437fd2115a449dcc00288da87e7b4958159420eb2bd94fae4546458def9743fbbc9e6915e6c2966
7
+ data.tar.gz: b769d5ff8efce153fb33ba56882fff41db37dba8a61c02423d42067b258a3b45a895e9ef006b770bc3257b924e029f49de8822e752242dc067ba9d9960e46bae
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ # By default, would enforce { key: value } rather than { :key => value }.
2
+ # AllCops:
3
+ # RunRailsCops: true
4
+
5
+ # Multi-line method chaining should be done with trailing dots.
6
+ Style/DotPosition:
7
+ EnforcedStyle: trailing
8
+
9
+ # ...
10
+ LineLength:
11
+ Max: 99
12
+
13
+ # Relax some of the cops for tests
14
+ Metrics/ClassLength:
15
+ Exclude:
16
+ - test/**/*.rb
17
+ Metrics/MethodLength:
18
+ Exclude:
19
+ - test/**/*.rb
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting one or more of the project maintainers. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ndr_dev_support.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2016 Public Health England
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ ## NdrDevSupport [![Build Status](https://travis-ci.org/PublicHealthEngland/ndr_dev_support.svg?branch=master)](https://travis-ci.org/PublicHealthEngland/ndr_dev_support)
2
+
3
+ This is the Public Health England (PHE) National Disease Registers (NDR) Developer Support ruby gem,
4
+ providing:
5
+
6
+ 1. rake tasks to manage code auditing of ruby based projects; and
7
+ 2. a rake task to limit Rubocop's output to changed (and related) code.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'ndr_dev_support', group: :development
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install ndr_dev_support
24
+
25
+ ## Usage
26
+
27
+ ### Code Auditing Rake Tasks
28
+
29
+ ndr_dev_support provides a mechanism to manage the state of routine code quality and security peer reviews. It should be used as part of wider quality and security policies.
30
+
31
+ It provides rake tasks to help manage the process of persisting the state of security reviews.
32
+
33
+ Once files have been reviewed as secure, the revision number for that file is stored in code_safety.yml. If used within a Rails app, this file is stored in the config/ folder, otherwise it is kept in the project's root folder.
34
+
35
+ Note: This feature works with svn and git repositories and svn, git-svn and git working copies.
36
+
37
+ For more details of the audit tasks available, execute:
38
+
39
+ $ rake -T audit
40
+
41
+ ### RuboCop filtering
42
+
43
+ ndr_dev_support provides rake tasks to enable more targeted use of RuboCop, to analyse only relevant code changes:
44
+ ```
45
+ $ rake rubocop:diff HEAD
46
+ $ rake rubocop:diff HEAD~3..HEAD~2
47
+ $ rake rubocop:diff HEAD~3..HEAD~2
48
+ $ rake rubocop:diff aef12fd4
49
+ $ rake rubocop:diff master
50
+ $ rake rubocop:diff path/to/file
51
+ $ rake rubocop:diff dir/
52
+ ```
53
+ As well as the primary `rubocop:diff` task, there are a number of convenience tasks provided:
54
+ ```
55
+ $ rake rubocop:diff:head
56
+ $ rake rubocop:diff:staged
57
+ $ rake rubocop:diff:unstaged
58
+ $ find . -iregex .*\.rake$ | xargs rake rubocop:diff:file
59
+ ```
60
+
61
+ To add development support tasks to your project, add this line to your application's Rakefile:
62
+
63
+ ```ruby
64
+ require 'ndr_dev_support/tasks'
65
+ ```
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PublicHealthEngland/ndr_dev_support. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
76
+
77
+ 1. Fork it ( https://github.com/PublicHealthEngland/ndr_dev_support/fork )
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create a new Pull Request
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
86
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'ndr_dev_support/tasks'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ desc 'Run tests'
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tnql'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/code_safety.yml ADDED
@@ -0,0 +1,91 @@
1
+ ---
2
+ file safety:
3
+ ".gitignore":
4
+ comments:
5
+ reviewed_by: timgentry
6
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
7
+ ".rubocop.yml":
8
+ comments:
9
+ reviewed_by: joshpencheon
10
+ safe_revision: e1ead45a8d1fd525f3a39cc4a87e6c0338c6b879
11
+ ".travis.yml":
12
+ comments:
13
+ reviewed_by: joshpencheon
14
+ safe_revision: 303ce774decdc5e19ce99051e4c94246313564d7
15
+ CODE_OF_CONDUCT.md:
16
+ comments:
17
+ reviewed_by: timgentry
18
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
19
+ Gemfile:
20
+ comments:
21
+ reviewed_by: timgentry
22
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
23
+ LICENSE.txt:
24
+ comments:
25
+ reviewed_by: timgentry
26
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
27
+ README.md:
28
+ comments:
29
+ reviewed_by: joshpencheon
30
+ safe_revision: 13cdf4eec8ea311ea480a90a3ba325a386db94e0
31
+ Rakefile:
32
+ comments:
33
+ reviewed_by: joshpencheon
34
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
35
+ bin/console:
36
+ comments:
37
+ reviewed_by: timgentry
38
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
39
+ bin/setup:
40
+ comments:
41
+ reviewed_by: timgentry
42
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
43
+ lib/ndr_dev_support.rb:
44
+ comments:
45
+ reviewed_by: timgentry
46
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
47
+ lib/ndr_dev_support/rubocop/executor.rb:
48
+ comments:
49
+ reviewed_by: joshpencheon
50
+ safe_revision: 301a0785d32fbc91b5fa175a0b4a4aed5bc5b8c1
51
+ lib/ndr_dev_support/rubocop/range_augmenter.rb:
52
+ comments:
53
+ reviewed_by: joshpencheon
54
+ safe_revision: fe5f0a693b77eeecaa39ff6fcf87ad59c4fb46e1
55
+ lib/ndr_dev_support/rubocop/range_finder.rb:
56
+ comments:
57
+ reviewed_by: joshpencheon
58
+ safe_revision: a8ecc0519a4abf9d464c49183863d65121dc8d0b
59
+ lib/ndr_dev_support/rubocop/reporter.rb:
60
+ comments:
61
+ reviewed_by: joshpencheon
62
+ safe_revision: fe5f0a693b77eeecaa39ff6fcf87ad59c4fb46e1
63
+ lib/ndr_dev_support/tasks.rb:
64
+ comments:
65
+ reviewed_by: joshpencheon
66
+ safe_revision: a55c971cb770a8e5dc4be7ed66663dd5d695fcd1
67
+ lib/ndr_dev_support/version.rb:
68
+ comments:
69
+ reviewed_by: joshpencheon
70
+ safe_revision: 9611e403f47171962308a7c82cd11b116c6534ee
71
+ lib/tasks/audit_code.rake:
72
+ comments: Identical to the version reviewed by josh.pencheon when contained within
73
+ ndr_support
74
+ reviewed_by: timgentry
75
+ safe_revision: 0d56ba443b2cddca5ba2d96ea61ec6f2b898436d
76
+ lib/tasks/rubocop.rake:
77
+ comments:
78
+ reviewed_by: joshpencheon
79
+ safe_revision: 13cdf4eec8ea311ea480a90a3ba325a386db94e0
80
+ ndr_dev_support.gemspec:
81
+ comments:
82
+ reviewed_by: joshpencheon
83
+ safe_revision: d61f29be0444859c092f4c0599cc48f5bea8f0ac
84
+ test/ndr_dev_support_test.rb:
85
+ comments:
86
+ reviewed_by: timgentry
87
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
88
+ test/test_helper.rb:
89
+ comments:
90
+ reviewed_by: timgentry
91
+ safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
@@ -0,0 +1,5 @@
1
+ require 'ndr_dev_support/version'
2
+
3
+ module NdrDevSupport
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+ require 'shellwords'
3
+
4
+ module NdrDevSupport
5
+ module Rubocop
6
+ # This class filters the Rubocop report of a file
7
+ # to only the given lines.
8
+ class Executor
9
+ def initialize(filename, lines)
10
+ @filename = filename
11
+ @lines = lines
12
+ end
13
+
14
+ def output
15
+ offenses.select do |offense|
16
+ @lines.include? offense['location']['line']
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def offenses
23
+ hash = JSON.parse(`rubocop --format json #{Shellwords.escape(@filename)}`)
24
+ hash['files'].first['offenses']
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ module NdrDevSupport
2
+ module Rubocop
3
+ # For a given file, and set of line ranges, computes a list of
4
+ # all lines covered, expanding the ranges to include full method
5
+ # defintions, and class/module headers.
6
+ class RangeAugmenter
7
+ require 'parser/current'
8
+
9
+ MODULE_TYPES = [:module, :class].freeze
10
+ METHOD_TYPES = [:def, :defs].freeze
11
+
12
+ attr_reader :filename
13
+
14
+ class << self
15
+ def augmented_lines_for(file_ranges)
16
+ output = {}
17
+ file_ranges.each do |file, ranges|
18
+ output[file] = new(file, ranges).lines
19
+ end
20
+ output
21
+ end
22
+ end
23
+
24
+ def initialize(filename, ranges)
25
+ @filename = filename
26
+ @lines = ranges.map(&:to_a).flatten
27
+ end
28
+
29
+ def augmented_lines
30
+ root = Parser::CurrentRuby.parse IO.read(filename)
31
+ nodes = extract_augmenting_nodes(root)
32
+
33
+ lines_covering(@lines, nodes)
34
+ end
35
+
36
+ private
37
+
38
+ def range_for(node)
39
+ expression = node.location.expression
40
+ start_line = expression.line
41
+ end_line, _column = expression.source_buffer.decompose_position(expression.end_pos)
42
+
43
+ start_line..end_line
44
+ end
45
+
46
+ def lines_covering(lines, nodes)
47
+ nodes.each do |node|
48
+ range = range_for(node)
49
+ next unless lines.detect { |line| range.cover?(line) }
50
+
51
+ if method?(node)
52
+ lines.concat(range.to_a)
53
+ elsif module?(node)
54
+ lines.push(range.begin)
55
+ end
56
+ end
57
+ lines.uniq.sort
58
+ end
59
+
60
+ def extract_augmenting_nodes(parent, result = [])
61
+ return result if dead_end?(parent)
62
+ result.push(parent) if method?(parent) || module?(parent)
63
+ parent.children.each { |node| extract_augmenting_nodes(node, result) }
64
+ result
65
+ end
66
+
67
+ def module?(node)
68
+ MODULE_TYPES.include? node.type
69
+ end
70
+
71
+ def method?(node)
72
+ METHOD_TYPES.include? node.type
73
+ end
74
+
75
+ def dead_end?(node)
76
+ return true unless node.is_a?(Parser::AST::Node)
77
+ location = node.location
78
+ !(location && location.expression)
79
+ end
80
+ end
81
+ end
82
+ end