Skip to content

ddddavis/Ruby-Capstone-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues


Logo

Javascript Linter

Ruby Capstone Project --> Build your own linter

Table of Contents

About The Project

This is the Ruby Capstone Project required at the end of Ruby module in Microverse Curriculum. It is a Javascript Linter with the purpose to check for simple Javascript errors

Rules

Strict Mode

Strict mode helps out in a couple ways:

  • It catches some common coding bloopers, throwing exceptions.
  • It prevents, or throws errors, when relatively "unsafe" actions are taken (such as gaining access to the global object).
  • It disables features that are confusing or poorly thought out.

Bad code:

a = "Hello World!";
console.log(a)
}

The above code will work because it is not in strict mode.

Good code:

"use strict";
a = "Hello World"; // Will throw a 'ReferenceError' because "a" is used without declaration
console.log(a);

Relational Operators

It is considered good practice to use the type-safe equality operators '===' and '!==' instead of their regular counterparts '==' and '!='.

For instance:

  false == '0'      // true
  false == 'false'  // false
  1 == '1'          // true
  0 == ''           // true
  0 == '0'          // true
  3 == '03'         // true

Bad code:

a == b
foo == true
bananas != 1
value == undefined
typeof foo == 'undefined'
'hello' != 'world'
0 == 0
true == true
foo == null

Good code:

a === b
foo === true
bananas !== 1
value === undefined
typeof foo === 'undefined'
'hello' !== 'world'
0 === 0
true === true
foo === null

Variable Declaration

ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the 'let' and 'const' keywords. Block scope is common in many other programming languages and helps programmers to avoid mistake such as:

var count = people.length;
var enoughFood = count > sandwiches.length;

if (enoughFood) {
    var count = sandwiches.length; // accidentally overriding the count variable
    console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
}

console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!"); // our count variable is no longer accurate

Bad code:

var x = "y";
var CONFIG = {};

Good code:

let x = "y";
const CONFIG = {};

Newline at the end of files

Trailing newlines in non-empty files are a common UNIX idiom. Benefits of trailing newlines include the ability to concatenate or append to files as well as output files to the terminal without interfering with shell prompts.

Bad code:

function doesSomething() {
  const foo = 2;
}

Good code:

function doesSomething() {
  const foo = 2;
}
// new line

Spacing

Consistency is an important part of any style guide. While it is a personal preference where to put the opening brace of blocks, it should be consistent across a whole project. Having an inconsistent style distracts the reader from seeing the important parts of the code.

Bad code:

if(variable2===variable3){
  console.log(true);
}else if(variable2!==variable3){
  console.log(false)
}else{
  console.log(false)
}

Good code:

if (variable2 === variable3) {
  console.log(true);
} else if (variable2 !== variable3) {
  console.log(false)
} else {
  console.log(false)
}

Instructions

To test out Javascript Linter you need to:

  • have Ruby installed on your computer

  • download or clone this repo:

    • Clone with SSH:
    git@github.com:davisdambis/Ruby-Capstone-Project.git
    
    
    • Clone with HTTPS:
    https://github.com/davisdambis/ruby-capstone-project.git
    
  • Navigate to root directory of the repo and run:

$ ruby /bin/main.rb path_to_file.js

Rspec testing

  • Run the command and see the output
$ rspec

Built With

This project was built using these technologies.

  • Ruby
  • Rubocop
  • Rspec
  • Strscan

Contributors

👤 Davis Dambis

Acknowledgements

📝 License

This project is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published