Skip to content

This project aims to use some of Ruby's inbuilt methods to build a JSON linter similar to ESLint. The project will continue to evolve and be updated. I hope you find it helpful.

License

Notifications You must be signed in to change notification settings

joshuaivie/mv-rb_JSON-Linter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Linter

Ruby is a beautiful programming language that was designed for programmer productivity. It comes feature-packed with numerous inbuilt classes and methods to make programming enjoyable for developers.

According to Wikipedia, JSON(JavaScript Object Notation) is an open standard file format and data interchange format. It uses human-readable text to store and transmit data objects. JSON files consist of attribute-value pairs and arrays (or other serializable values).

In today's development world, JSON is one of the popular data formats. Although it was derived from JavaScript, it a language-independent format. Many languages come with an inbuilt JSON parser. It is also a light-weight format and, it is human-readable.

This project aims to use some of Ruby's inbuilt methods to build a JSON linter. The project will continue to evolve and be updated. I hope you find it helpful.



Linter Description📄

This JSON linter checks for the following errors/warnings:

  1. Check empty line error
  2. Check for missing/unexpected tags i.e. '( )', '[ ]', and '{ }'
  3. Check for the wrong indentation
  4. Check for the malformed fractions
  5. Check for the leading zeros
  6. Check new line at end of JSON

Below you can see good, bad and empty JSON files and their test results on the console


Well formed JSON passes the test successfully!

# Well Formed JSON
{
  "firstName": "John",
  "lastName": "Snow",
  "age": 25,
  "children": [],
  "spouse": null,
  "address": {
    "street": "7504 Taylor Drive",
    "city": "New York City",
  },
  "phoneNumbers": [
    {
      "type": "mobile",
      "number": "212 555-3346"
    }
  ]
}

Console output


Badly formed JSON fails the test

# Badly formed JSON
{
  "openObject": {
  "improperIndent": "string 0"
    "leadingZero": {"example": 01},

    "unterminatedFraction": {"example": .1},
    "openObject": {
      "street": "7504 Taylor Drive",
      "city": "New York City",
      "state": "New York",
      "postalCode": "11238"
  ]

Console output


Empty JSON file shows a warning to the user!

# Empty JSON File



Console output


Content

Built With

  • Ruby
  • RSpec

Live Demo

You can check out the live demo here

Getting Started

To get a local copy up and running, follow these simple example steps.

  • Install the prerequisites on your local machine
  • Clone the repository to your local machine as described in the setup section
  • run the enumerable.rb file using ruby in your terminal as described in the usage section

Prerequisites

  1. Code Editor
  2. Terminal (Bash)
  3. Git
  4. Ruby

Setup

  • Open your terminal and navigate to the location in which you would like to setup your copy of the project.
  • Run the following command in your terminal
git clone https://github.com/joshuaivie/mv-rb_JSON-Linter/

Usage

  • Ensure you're in the directory in which you've set up the project
  • Run the following command replacing the relative file path with the path of the file you wish to test
bin/main.rb [./relative/file/path]

Testing

This project uses the ruby spec gem for testing.

gem install rspec &&  cd mv-rb_JSON-Linter && rspec

Author

👤 Joshua Ivie

🤝 Contributing

Contributions, issues, and feature requests are welcome!

Feel free to check the issues page.

Show your support

Give a ⭐️ if you like this project!

📝 License

This project is MIT licensed.

About

This project aims to use some of Ruby's inbuilt methods to build a JSON linter similar to ESLint. The project will continue to evolve and be updated. I hope you find it helpful.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages