file_charset_validator 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 +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/e2e_test.sh +13 -0
- data/exe/file_charset +6 -0
- data/exe/file_charset_validator +24 -0
- data/file_charset_validator.gemspec +29 -0
- data/lib/file_charset_validator/cli.rb +29 -0
- data/lib/file_charset_validator/helper.rb +7 -0
- data/lib/file_charset_validator/version.rb +3 -0
- data/lib/file_charset_validator.rb +10 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c387d93de97961c258c907c60e164013073a7bacbf3de84f7a2784ba23b4ad8b
|
4
|
+
data.tar.gz: e129371b71f1ea57cf80450ecc5a93333b05eac522501be2a556d05a8bc64212
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b476fb8e5c5fcb1431e188cb102936872f018545f221fa23b60a1dacadc751e74c23476734bb330b0d4e604c19eb70f5aacaaf4d319688fd4858f34da4e04642
|
7
|
+
data.tar.gz: 53b3dfec9eeb342a811217ca1a2f3db7c33452d6d9ae864017a4670474b77553477c8fff327ca16c49b11b94c5573f40abcfe449393f7b7d6d28a6a1a19a5970
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
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 me@yammer.jp. 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 [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
file_charset_validator (0.1.0)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
rake (12.3.3)
|
12
|
+
rspec (3.10.0)
|
13
|
+
rspec-core (~> 3.10.0)
|
14
|
+
rspec-expectations (~> 3.10.0)
|
15
|
+
rspec-mocks (~> 3.10.0)
|
16
|
+
rspec-core (3.10.2)
|
17
|
+
rspec-support (~> 3.10.0)
|
18
|
+
rspec-expectations (3.10.2)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.10.0)
|
21
|
+
rspec-mocks (3.10.3)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-support (3.10.3)
|
25
|
+
thor (1.2.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
file_charset_validator!
|
32
|
+
rake (~> 12.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Keisuke Nakayama
|
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,56 @@
|
|
1
|
+
# file_charset_validator
|
2
|
+
|
3
|
+
file_charset_validator is CLI tool to validate text files' encoding.
|
4
|
+
|
5
|
+
This is implemented by ruby, and distributed as a gem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install it yourself as:
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install file_charset_validator
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
|
18
|
+
```sh
|
19
|
+
$ file_charset_validator --encoding UTF_8 path/to/file/1 path/to/file/2
|
20
|
+
```
|
21
|
+
|
22
|
+
If the character codes of `path/to/file/1` and `path/to/file/2` are both UTF_8, it will exit normally.
|
23
|
+
Otherwise, it will output a message and exit abnormally.
|
24
|
+
|
25
|
+
|
26
|
+
### Options
|
27
|
+
|
28
|
+
`--encoding` (`-e`)
|
29
|
+
|
30
|
+
You can specify the character encoding to be verified.
|
31
|
+
The character encoding that can be specified is defined as a constant in the encoding class of the ruby built-in library.
|
32
|
+
|
33
|
+
### Arguments
|
34
|
+
|
35
|
+
`<path, ...>`
|
36
|
+
|
37
|
+
You can specify one or more file paths to be verified.
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
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.
|
42
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/file_charset_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/file_charset_validator/blob/master/CODE_OF_CONDUCT.md).
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
53
|
+
|
54
|
+
## Code of Conduct
|
55
|
+
|
56
|
+
Everyone interacting in the FileCharset project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/file_charset_validator/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "file_charset_validator"
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/e2e_test.sh
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
bundle exec file_charset_validator --encoding UTF_8 spec/sample/rashomon/UTF_8.txt spec/sample/rashomon/UTF_8.txt spec/sample/rashomon/UTF_8.txt
|
4
|
+
! bundle exec file_charset_validator --encoding UTF_8 spec/sample/rashomon/UTF_8.txt spec/sample/rashomon/UTF_8.txt spec/sample/rashomon/EUC_JP.txt
|
5
|
+
! bundle exec file_charset_validator --encoding UTF_8 spec/sample/rashomon/UTF_8.txt spec/sample/rashomon/UTF_8.txt spec/sample/rashomon/Shift_JIS.txt
|
6
|
+
|
7
|
+
bundle exec file_charset_validator --encoding Shift_JIS spec/sample/rashomon/Shift_JIS.txt spec/sample/rashomon/Shift_JIS.txt spec/sample/rashomon/Shift_JIS.txt
|
8
|
+
! bundle exec file_charset_validator --encoding UTF_8 spec/sample/rashomon/Shift_JIS.txt spec/sample/rashomon/Shift_JIS.txt spec/sample/rashomon/EUC_JP.txt
|
9
|
+
! bundle exec file_charset_validator --encoding UTF_8 spec/sample/rashomon/Shift_JIS.txt spec/sample/rashomon/Shift_JIS.txt spec/sample/rashomon/UTF_8.txt
|
10
|
+
|
11
|
+
bundle exec file_charset_validator --encoding EUC_JP spec/sample/rashomon/EUC_JP.txt spec/sample/rashomon/EUC_JP.txt spec/sample/rashomon/EUC_JP.txt
|
12
|
+
! bundle exec file_charset_validator --encoding EUC_JP spec/sample/rashomon/EUC_JP.txt spec/sample/rashomon/EUC_JP.txt spec/sample/rashomon/Shift_JIS.txt
|
13
|
+
! bundle exec file_charset_validator --encoding EUC_JP spec/sample/rashomon/EUC_JP.txt spec/sample/rashomon/EUC_JP.txt spec/sample/rashomon/UTF_8.txt
|
data/exe/file_charset
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "file_charset_validator"
|
4
|
+
require "file_charset_validator/cli.rb"
|
5
|
+
|
6
|
+
|
7
|
+
=begin
|
8
|
+
if ARGV.empty?
|
9
|
+
STDOUT.puts "Usage: file_charset_validator --encoding <encoding-name> [path, path, ...]"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
if ARGV[0] == "--encoding"
|
14
|
+
encoding = ARGV[1]
|
15
|
+
paths = ARGV[2..-1]
|
16
|
+
else
|
17
|
+
encoding = "UTF_8"
|
18
|
+
paths = ARGV
|
19
|
+
end
|
20
|
+
|
21
|
+
exit FileCharsetValidator.check_paths_with_string_encoding(paths, encoding) ? 0 : 1
|
22
|
+
=end
|
23
|
+
|
24
|
+
CLI.start(ARGV)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/file_charset_validator/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "file_charset_validator"
|
5
|
+
spec.version = FileCharsetValidator::VERSION
|
6
|
+
spec.authors = ["Keisuke Nakayama"]
|
7
|
+
spec.email = ["me@yammer.jp"]
|
8
|
+
|
9
|
+
|
10
|
+
spec.summary = "Validate file charset"
|
11
|
+
spec.description = "Validate what the character set of the specified file is. Is it UTF-8? or Shift-JIS? or ..."
|
12
|
+
spec.homepage = "https://github.com/yammerjp/file_charset_validator"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/yammerjp/file_charset_validator"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/yammerjp/file_charset_validator/blob/main/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
spec.add_dependency "thor"
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "file_charset_validator"
|
2
|
+
require "thor"
|
3
|
+
require "file_charset_validator/helper.rb"
|
4
|
+
|
5
|
+
class CLI < Thor
|
6
|
+
default_command :check
|
7
|
+
|
8
|
+
desc 'check [option] <path, ...>', 'Check the character set of the file specified by the arguments'
|
9
|
+
option :encoding, type: :string, aliases: '-e', desc: 'Encoding name (ex. UTF_8, Shift_JIS, EUC_JP)'
|
10
|
+
def check(*paths)
|
11
|
+
if paths.empty?
|
12
|
+
self.help
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
encoding = get_encoding(options[:encoding] || 'UTF_8')
|
17
|
+
if encoding.nil?
|
18
|
+
STDERR.puts "Unknown encoding: #{options[:encoding]}"
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
invalid_paths = FileCharsetValidator.invalid_encoding_paths(paths, encoding)
|
23
|
+
head = "Invalid encoding file: "
|
24
|
+
if !invalid_paths.empty?
|
25
|
+
STDERR.puts "#{head}#{invalid_paths.join("\n#{head}")}"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "file_charset_validator/version"
|
2
|
+
require "file_charset_validator/helper.rb"
|
3
|
+
|
4
|
+
class FileCharsetValidator
|
5
|
+
def self.invalid_encoding_paths(paths, encoding)
|
6
|
+
paths.reject do |path|
|
7
|
+
IO.binread(path.chomp).force_encoding(encoding).valid_encoding?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: file_charset_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keisuke Nakayama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Validate what the character set of the specified file is. Is it UTF-8?
|
28
|
+
or Shift-JIS? or ...
|
29
|
+
email:
|
30
|
+
- me@yammer.jp
|
31
|
+
executables:
|
32
|
+
- file_charset
|
33
|
+
- file_charset_validator
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".gitignore"
|
38
|
+
- ".rspec"
|
39
|
+
- ".travis.yml"
|
40
|
+
- CHANGELOG.md
|
41
|
+
- CODE_OF_CONDUCT.md
|
42
|
+
- Gemfile
|
43
|
+
- Gemfile.lock
|
44
|
+
- LICENSE.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- bin/console
|
48
|
+
- bin/setup
|
49
|
+
- e2e_test.sh
|
50
|
+
- exe/file_charset
|
51
|
+
- exe/file_charset_validator
|
52
|
+
- file_charset_validator.gemspec
|
53
|
+
- lib/file_charset_validator.rb
|
54
|
+
- lib/file_charset_validator/cli.rb
|
55
|
+
- lib/file_charset_validator/helper.rb
|
56
|
+
- lib/file_charset_validator/version.rb
|
57
|
+
homepage: https://github.com/yammerjp/file_charset_validator
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata:
|
61
|
+
homepage_uri: https://github.com/yammerjp/file_charset_validator
|
62
|
+
source_code_uri: https://github.com/yammerjp/file_charset_validator
|
63
|
+
changelog_uri: https://github.com/yammerjp/file_charset_validator/blob/main/CHANGELOG.md
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.3.0
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.1.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Validate file charset
|
83
|
+
test_files: []
|