Skip to content

Commit 0745b68

Browse files
committed
added the more specific name to methods and created private methods for the lint class
1 parent fd0762d commit 0745b68

File tree

7 files changed

+185
-57
lines changed

7 files changed

+185
-57
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.rubocop.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ Metrics/BlockLength:
2424

2525
Style/Documentation:
2626
Enabled: false
27-
Style/GlobalVars:
28-
Enabled: false
29-
Style/GuardClause:
30-
Enabled: false
3127
Style/ClassAndModuleChildren:
3228
Enabled: false
3329
Style/MutableConstant:

bin/main.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
file = './file.css'
66
f = File.open(file, 'r')
7-
Test.new(f)
7+
Error.new(f)
88
f.close

lib/lint.rb

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
# frozen_string_literal: true
22

3-
require_relative 'module'
4-
include Bot
3+
require_relative 'tests'
4+
include Tests
55

6-
class Test
7-
attr_reader :errors
8-
attr_accessor :i
6+
class Error
7+
attr_writer :errors
8+
attr_accessor :line
99
def initialize(str)
1010
@temp = str
11-
$i = 1
12-
checks
11+
@line = 1
12+
@errors = []
13+
run
14+
show
1315
end
1416

15-
def engine(code)
16-
(1..5).each do |i|
17-
Bot.run(i, code)
17+
def run
18+
@temp.each_line do |x|
19+
test_cases(x)
20+
@line += 1
1821
end
1922
end
2023

21-
def checks
22-
@temp.each_line do |x|
23-
engine(x)
24-
$i += 1
24+
def show
25+
@errors.each do |x|
26+
puts x
2527
end
2628
end
29+
30+
private
31+
32+
def test_cases(str)
33+
@errors << "There should be a new line after '{' on line: #{@line}" if Tests.new_line_check1(str)
34+
@errors << "There shoul a space before '{' on line: #{@line}" if Tests.space_check1(str)
35+
@errors << "The line should start with a sapce on line: #{@line}" if Tests.space_check2(str)
36+
@errors << "The correct assignment operator should be used on line: #{@line}" if Tests.assignment_check(str)
37+
@errors << "The line should end with a ';' on line: #{@line}" if Tests.ending_line_check(str)
38+
end
2739
end

lib/module.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

lib/tests.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
3+
module Tests
4+
def self.new_line_check1(str)
5+
return unless str.match(/.+{/)
6+
7+
str.match(/.+{$/)
8+
end
9+
10+
def self.space_check1(str)
11+
return unless str.match(/.+{/)
12+
13+
str.match(/.+\s{1}+{/)
14+
end
15+
16+
def self.capital_letter_check(str)
17+
return unless str.match(/.+[a-z]+.+.+./)
18+
19+
str.match(/[A-Z]/)
20+
end
21+
22+
def self.space_check2(str)
23+
return unless str.match(/.+[a-z]+.+.+./)
24+
25+
str.match(/\s{2}+[a-z]+.+.+./)
26+
end
27+
28+
def self.assignment_check(str)
29+
return unless str.match(/.+[a-z]+.+.+./)
30+
31+
str.match(/.+[a-z]+.+:+.+.+./)
32+
end
33+
34+
def self.ending_line_check(str)
35+
return unless str.match(/.+[a-z]+.+.+./)
36+
37+
str.match(/[a-z]+.+.+\s+.+;$/)
38+
end
39+
40+
def self.new_line_check2(str)
41+
return unless str.match(/.+[a-z]+.+.+./)
42+
43+
str.match(/[a-z]+.+:+\s+.+;\R/)
44+
end
45+
46+
def self.single_character_check(str)
47+
return unless str.match(/}/)
48+
49+
str.match(/^}/)
50+
end
51+
52+
def self.empty_line_check(str)
53+
return unless str.match(/}/)
54+
55+
str.match(/^}\R$/)
56+
end
57+
end

spec/spec_helper.rb

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# frozen_string_literal: true
2+
3+
# This file was generated by the `rspec --init` command. Conventionally, all
4+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5+
# The generated `.rspec` file contains `--require spec_helper` which will cause
6+
# this file to always be loaded, without a need to explicitly require it in any
7+
# files.
8+
#
9+
# Given that it is always loaded, you are encouraged to keep this file as
10+
# light-weight as possible. Requiring heavyweight dependencies from this file
11+
# will add to the boot time of your test suite on EVERY test run, even for an
12+
# individual file that may not need all of that loaded. Instead, consider making
13+
# a separate helper file that requires the additional dependencies and performs
14+
# the additional setup, and require it from the spec files that actually need
15+
# it.
16+
#
17+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18+
RSpec.configure do |config|
19+
# rspec-expectations config goes here. You can use an alternate
20+
# assertion/expectation library such as wrong or the stdlib/minitest
21+
# assertions if you prefer.
22+
config.expect_with :rspec do |expectations|
23+
# This option will default to `true` in RSpec 4. It makes the `description`
24+
# and `failure_message` of custom matchers include text for helper methods
25+
# defined using `chain`, e.g.:
26+
# be_bigger_than(2).and_smaller_than(4).description
27+
# # => "be bigger than 2 and smaller than 4"
28+
# ...rather than:
29+
# # => "be bigger than 2"
30+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31+
end
32+
33+
# rspec-mocks config goes here. You can use an alternate test double
34+
# library (such as bogus or mocha) by changing the `mock_with` option here.
35+
config.mock_with :rspec do |mocks|
36+
# Prevents you from mocking or stubbing a method that does not exist on
37+
# a real object. This is generally recommended, and will default to
38+
# `true` in RSpec 4.
39+
mocks.verify_partial_doubles = true
40+
end
41+
42+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43+
# have no way to turn it off -- the option exists only for backwards
44+
# compatibility in RSpec 3). It causes shared context metadata to be
45+
# inherited by the metadata hash of host groups and examples, rather than
46+
# triggering implicit auto-inclusion in groups with matching metadata.
47+
config.shared_context_metadata_behavior = :apply_to_host_groups
48+
49+
# The settings below are suggested to provide a good initial experience
50+
# with RSpec, but feel free to customize to your heart's content.
51+
# # This allows you to limit a spec run to individual examples or groups
52+
# # you care about by tagging them with `:focus` metadata. When nothing
53+
# # is tagged with `:focus`, all examples get run. RSpec also provides
54+
# # aliases for `it`, `describe`, and `context` that include `:focus`
55+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56+
# config.filter_run_when_matching :focus
57+
#
58+
# # Allows RSpec to persist some state between runs in order to support
59+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
60+
# # you configure your source control system to ignore this file.
61+
# config.example_status_persistence_file_path = "spec/examples.txt"
62+
#
63+
# # Limits the available syntax to the non-monkey patched syntax that is
64+
# # recommended. For more details, see:
65+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68+
# config.disable_monkey_patching!
69+
#
70+
# # This setting enables warnings. It's recommended, but in some cases may
71+
# # be too noisy due to issues in dependencies.
72+
# config.warnings = true
73+
#
74+
# # Many RSpec users commonly either run the entire suite or an individual
75+
# # file, and it's useful to allow more verbose output when running an
76+
# # individual spec file.
77+
# if config.files_to_run.one?
78+
# # Use the documentation formatter for detailed output,
79+
# # unless a formatter has already been configured
80+
# # (e.g. via a command-line flag).
81+
# config.default_formatter = "doc"
82+
# end
83+
#
84+
# # Print the 10 slowest examples and example groups at the
85+
# # end of the spec run, to help surface which specs are running
86+
# # particularly slow.
87+
# config.profile_examples = 10
88+
#
89+
# # Run specs in random order to surface order dependencies. If you find an
90+
# # order dependency and want to debug it, you can fix the order by providing
91+
# # the seed, which is printed after each run.
92+
# # --seed 1234
93+
# config.order = :random
94+
#
95+
# # Seed global randomization in this process using the `--seed` CLI option.
96+
# # Setting this allows you to use `--seed` to deterministically reproduce
97+
# # test failures related to randomization by passing the same `--seed` value
98+
# # as the one that triggered the failure.
99+
# Kernel.srand config.seed
100+
end

0 commit comments

Comments
 (0)