cucumber-unused_css 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +43 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +20 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/cucumber-unused_css.gemspec +50 -0
- data/lib/cucumber/unused_css.rb +14 -0
- data/lib/cucumber/unused_css/checker.rb +116 -0
- data/lib/cucumber/unused_css/version.rb +7 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 065c49384162db5e523569eb8d67aad78b059609e5dd6eb52e7f2009b9248145
|
4
|
+
data.tar.gz: f02ab8ede7024673111277880807e37a36c6461d184ff9fd4a8571f15a61e9ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f9131621bda1e9cd13bbf5f9167b886d19e354ecc275dc4dc7fe0951f023d3ac154903e9fb7e6d0cb74eeeddf97752e8e7ad8b55246fd810b9ccc3a18bfd57a
|
7
|
+
data.tar.gz: 729aed70eac72ca311bc89761f20f745d3d700597268247b3065c48266191de8bbc0cc591dde844973313d2fb2fe0258bcd004570162a370a1c4eb03f58882d0
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
image: ruby:2.5
|
3
|
+
|
4
|
+
stages:
|
5
|
+
- prepare
|
6
|
+
- test
|
7
|
+
|
8
|
+
cache: &dependencies
|
9
|
+
untracked: true
|
10
|
+
key: ${CI_COMMIT_REF_SLUG}
|
11
|
+
policy: pull
|
12
|
+
paths:
|
13
|
+
- 'vendor/'
|
14
|
+
|
15
|
+
before_script:
|
16
|
+
- bundle install --path=vendor
|
17
|
+
|
18
|
+
# Bundle stage
|
19
|
+
# ======================================
|
20
|
+
|
21
|
+
bundle:
|
22
|
+
stage: prepare
|
23
|
+
script:
|
24
|
+
- echo "This job only fills the cache"
|
25
|
+
cache:
|
26
|
+
<<: *dependencies
|
27
|
+
policy: push
|
28
|
+
|
29
|
+
# Testing stage
|
30
|
+
# ======================================
|
31
|
+
|
32
|
+
rubocop:
|
33
|
+
stage: test
|
34
|
+
script: bundle exec rubocop
|
35
|
+
dependencies:
|
36
|
+
- bundle
|
37
|
+
|
38
|
+
rspec:
|
39
|
+
stage: test
|
40
|
+
script:
|
41
|
+
- bundle exec rspec
|
42
|
+
dependencies:
|
43
|
+
- bundle
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
require:
|
3
|
+
- rubocop-performance
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: 2.5.1
|
8
|
+
NewCops: enable
|
9
|
+
|
10
|
+
Layout/HashAlignment:
|
11
|
+
EnforcedColonStyle: table
|
12
|
+
EnforcedHashRocketStyle: table
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Exclude:
|
19
|
+
- cucumber-unused_css.gemspec
|
20
|
+
- spec/**/*_spec.rb
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 12
|
24
|
+
|
25
|
+
Style/ClassAndModuleChildren:
|
26
|
+
Exclude:
|
27
|
+
- spec/**/*
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/TrailingCommaInArrayLiteral:
|
33
|
+
EnforcedStyleForMultiline: comma
|
34
|
+
|
35
|
+
Style/TrailingCommaInHashLiteral:
|
36
|
+
EnforcedStyleForMultiline: comma
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
<!-- Format:
|
6
|
+
## [0.0.1] - 2019-01-01 - Release description
|
7
|
+
|
8
|
+
### Added
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
### Improved
|
13
|
+
|
14
|
+
### Removed
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
-->
|
18
|
+
|
19
|
+
|
20
|
+
## [0.1.0] - 2020-09-17 - Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at manu@experimentslabs.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Manuel Tancoigne
|
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,110 @@
|
|
1
|
+
# Cucumber::UnusedCss
|
2
|
+
|
3
|
+
This gem aims to help you find unused CSS in your projects by checking selectors of the visited page in Cucumber steps.
|
4
|
+
|
5
|
+
Currently, it has been tested on a Rails application, but _should_ work in other setups.
|
6
|
+
|
7
|
+
This project is young, MRs are welcome to polish and/or improve it.
|
8
|
+
|
9
|
+
Sample output:
|
10
|
+
|
11
|
+
```text
|
12
|
+
103 scenarios (3 failed, 100 passed)
|
13
|
+
660 steps (2 failed, 2 skipped, 656 passed)
|
14
|
+
13m30.584s
|
15
|
+
|
16
|
+
Randomized with seed 1861
|
17
|
+
|
18
|
+
CSS selectors summary
|
19
|
+
---------------------
|
20
|
+
> Ignored selectors: 253
|
21
|
+
> Used selectors: 239
|
22
|
+
> Unused selectors: 238
|
23
|
+
> Total selectors: 730
|
24
|
+
|
25
|
+
Lists saved in tmp as css_*.yml
|
26
|
+
```
|
27
|
+
|
28
|
+
## Notes on CI
|
29
|
+
|
30
|
+
Don't use this in CI: results depend on your Cucumber steps, so unless you wrote specific steps that covers all your use cases, you will get false positives. And it's slow (see "Benchmark")
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
gem 'cucumber-unused_css', required: false
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
```shell
|
43
|
+
bundle
|
44
|
+
```
|
45
|
+
|
46
|
+
## Cucumber configuration
|
47
|
+
|
48
|
+
We use two Cucumber hooks: `AfterStep` and `at_exit`. As the script really slows down the runs, you should not enable it by default. Edit your your preferred Cucumber configuration file and add:
|
49
|
+
|
50
|
+
```rb
|
51
|
+
require 'cucumber/unused_css'
|
52
|
+
|
53
|
+
# Collect stylesheets and search for unused styles in visited pages
|
54
|
+
if ENV['UNUSED_CSS'] == 'true'
|
55
|
+
# Specify output for summary files
|
56
|
+
Cucumber::UnusedCss::Checker.prepare output_directory: Rails.root.join('tmp')
|
57
|
+
# Add regexes for custom selectors to ignore
|
58
|
+
Cucumber::UnusedCss::Checker.ignore [
|
59
|
+
# Libraries
|
60
|
+
/^\.CodeMirror/,
|
61
|
+
/^\.cm-/,
|
62
|
+
/^\.hljs/,
|
63
|
+
]
|
64
|
+
|
65
|
+
# Ran after each step
|
66
|
+
AfterStep do
|
67
|
+
# Collect CSS stylesheets and add selectors to the list
|
68
|
+
Cucumber::UnusedCss::Checker.load_css_in_page html, Capybara.current_url
|
69
|
+
# Check for unused selectors in the page (if the step visited one)
|
70
|
+
Cucumber::UnusedCss::Checker.check_selectors page
|
71
|
+
end
|
72
|
+
|
73
|
+
# Ran at shutdown
|
74
|
+
at_exit do
|
75
|
+
# Save summary files and display a small text
|
76
|
+
Cucumber::UnusedCss::Checker.save_and_summarize
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
## Usage
|
82
|
+
|
83
|
+
Depending on the environment variable you used, simply launch:
|
84
|
+
|
85
|
+
```shell
|
86
|
+
UNUSED_CSS=true bundle exec cucumber
|
87
|
+
```
|
88
|
+
|
89
|
+
## Benchmark
|
90
|
+
|
91
|
+
- Normal run, headless: **3m17.307s**
|
92
|
+
- Search for unused CSS, headless: **20m10.783s**
|
93
|
+
|
94
|
+
## Development
|
95
|
+
|
96
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
97
|
+
|
98
|
+
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).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and merge requests are welcome on GitLab at https://gitlab.com/experimentslabs/cucumber-unused-css. 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.
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
107
|
+
|
108
|
+
## Code of Conduct
|
109
|
+
|
110
|
+
Everyone interacting in the Cucumber::UnusedCss project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'cucumber/unused_css'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'cucumber/unused_css/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.required_ruby_version = '>= 2.5.1'
|
9
|
+
spec.name = 'cucumber-unused_css'
|
10
|
+
spec.version = Cucumber::UnusedCss::VERSION
|
11
|
+
spec.authors = ['Manuel Tancoigne']
|
12
|
+
spec.email = ['manu@experimentslabs.com']
|
13
|
+
|
14
|
+
spec.summary = 'Checks for unused CSS selectors.'
|
15
|
+
spec.description = 'Checks for unused CSS selectors after every Cucumber step.'
|
16
|
+
spec.homepage = 'https://gitlab.com/experimentslabs/cucumber-unused-css/'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
23
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
24
|
+
spec.metadata['bug_tracker_uri'] = 'https://gitlab.com/experimentslabs/cucumber-unused-css/issues'
|
25
|
+
spec.metadata['changelog_uri'] = 'https://gitlab.com/experimentslabs/cucumber-unused-css/-/blob/master/CHANGELOG.md'
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ['lib']
|
39
|
+
|
40
|
+
spec.add_dependency 'capybara', '~> 3'
|
41
|
+
spec.add_dependency 'css_parser', '~> 1.7'
|
42
|
+
spec.add_dependency 'cucumber', '~> 4.1'
|
43
|
+
|
44
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
45
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
46
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
47
|
+
spec.add_development_dependency 'rubocop', '~> 0.89'
|
48
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.7'
|
49
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.43'
|
50
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cucumber/unused_css/version'
|
4
|
+
require 'cucumber/unused_css/checker'
|
5
|
+
|
6
|
+
module Cucumber
|
7
|
+
module UnusedCss
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
def self.root
|
11
|
+
Pathname.new File.dirname(File.dirname(__dir__))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'css_parser'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module Cucumber
|
7
|
+
module UnusedCss
|
8
|
+
class Checker
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def self.prepare(output_directory:)
|
12
|
+
@output_directory = output_directory
|
13
|
+
@used_selectors = []
|
14
|
+
@unused_selectors = []
|
15
|
+
@css_files = []
|
16
|
+
@ignored_selectors = []
|
17
|
+
@ignores = [
|
18
|
+
/^@(font-face|(-moz-|-webkit-)?keyframes)/,
|
19
|
+
/^\*$/,
|
20
|
+
/:active/,
|
21
|
+
/:hover/,
|
22
|
+
/::(before|after)/,
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.ignore(list = [])
|
27
|
+
@ignores += list
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.load_css_in_page(html_string, current_url)
|
31
|
+
html_page = Nokogiri::HTML(html_string)
|
32
|
+
|
33
|
+
html_page.css('link[rel="stylesheet"]').each do |file_tag|
|
34
|
+
if file_tag['href'].match?(/^https?:/)
|
35
|
+
css_file_url = file_tag['href']
|
36
|
+
else
|
37
|
+
uri = URI.parse(current_url)
|
38
|
+
css_file_url = "#{uri.scheme}://#{uri.host}:#{uri.port}#{file_tag['href']}"
|
39
|
+
end
|
40
|
+
|
41
|
+
load_selectors css_file_url
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.check_selectors(page)
|
46
|
+
new_used_selectors = []
|
47
|
+
@unused_selectors.each do |selector|
|
48
|
+
new_used_selectors.push selector if page.has_css?(selector, wait: 0)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Add newly used selectors
|
52
|
+
@used_selectors += new_used_selectors
|
53
|
+
|
54
|
+
# Remove from unused list
|
55
|
+
@unused_selectors -= new_used_selectors
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.save_and_summarize
|
59
|
+
@unused_selectors.sort!
|
60
|
+
@used_selectors.sort!
|
61
|
+
@ignored_selectors.sort!
|
62
|
+
|
63
|
+
write_files
|
64
|
+
summarize
|
65
|
+
end
|
66
|
+
|
67
|
+
class << self
|
68
|
+
attr_reader :unused_selectors, :used_selectors, :ignored_selectors
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def load_selectors(url)
|
73
|
+
return if @css_files.include? url
|
74
|
+
|
75
|
+
parser = CssParser::Parser.new
|
76
|
+
parser.load_uri! url
|
77
|
+
parser.each_selector do |selector|
|
78
|
+
# Ignore some CSS directive that are not selectors
|
79
|
+
if ignore? selector
|
80
|
+
@ignored_selectors.push selector
|
81
|
+
next
|
82
|
+
end
|
83
|
+
|
84
|
+
@unused_selectors.push(selector) unless @used_selectors.include?(selector) || @unused_selectors.include?(selector)
|
85
|
+
end
|
86
|
+
|
87
|
+
@css_files.push url
|
88
|
+
end
|
89
|
+
|
90
|
+
def ignore?(selector)
|
91
|
+
@ignores.each do |regexp|
|
92
|
+
return true if selector.match? regexp
|
93
|
+
end
|
94
|
+
|
95
|
+
false
|
96
|
+
end
|
97
|
+
|
98
|
+
def write_files
|
99
|
+
File.write @output_directory.join('css_unused_selectors.yml'), @unused_selectors.to_yaml
|
100
|
+
File.write @output_directory.join('css_used_selectors.yml'), @used_selectors.to_yaml
|
101
|
+
File.write @output_directory.join('css_ignored_selectors.yml'), @ignored_selectors.to_yaml
|
102
|
+
end
|
103
|
+
|
104
|
+
def summarize
|
105
|
+
puts "\nCSS selectors summary"
|
106
|
+
puts '---------------------'
|
107
|
+
puts " > Ignored selectors: #{@ignored_selectors.count}"
|
108
|
+
puts " > Used selectors: #{@used_selectors.count}"
|
109
|
+
puts " > Unused selectors: #{@unused_selectors.count}"
|
110
|
+
puts " > Total selectors: #{@used_selectors.count + @unused_selectors.count + @ignored_selectors.count}"
|
111
|
+
puts "\nLists saved in tmp as css_*.yml"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cucumber-unused_css
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manuel Tancoigne
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: css_parser
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.89'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.89'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-performance
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.7'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.43'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.43'
|
139
|
+
description: Checks for unused CSS selectors after every Cucumber step.
|
140
|
+
email:
|
141
|
+
- manu@experimentslabs.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".gitlab-ci.yml"
|
148
|
+
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
150
|
+
- ".ruby-version"
|
151
|
+
- ".travis.yml"
|
152
|
+
- CHANGELOG.md
|
153
|
+
- CODE_OF_CONDUCT.md
|
154
|
+
- Gemfile
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- bin/console
|
159
|
+
- bin/setup
|
160
|
+
- cucumber-unused_css.gemspec
|
161
|
+
- lib/cucumber/unused_css.rb
|
162
|
+
- lib/cucumber/unused_css/checker.rb
|
163
|
+
- lib/cucumber/unused_css/version.rb
|
164
|
+
homepage: https://gitlab.com/experimentslabs/cucumber-unused-css/
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata:
|
168
|
+
homepage_uri: https://gitlab.com/experimentslabs/cucumber-unused-css/
|
169
|
+
source_code_uri: https://gitlab.com/experimentslabs/cucumber-unused-css/
|
170
|
+
bug_tracker_uri: https://gitlab.com/experimentslabs/cucumber-unused-css/issues
|
171
|
+
changelog_uri: https://gitlab.com/experimentslabs/cucumber-unused-css/-/blob/master/CHANGELOG.md
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 2.5.1
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.7.6
|
189
|
+
signing_key:
|
190
|
+
specification_version: 4
|
191
|
+
summary: Checks for unused CSS selectors.
|
192
|
+
test_files: []
|