Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eslint and Prettier with precommit task #36

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = tab
insert_final_newline = true
max_line_length = 130
trim_trailing_whitespace = true

[*.md]
max_line_length = 130
trim_trailing_whitespace = true
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"indent": ["error", "tab"],
"no-tabs": ["error", { "allowIndentationTabs": true }],
"max-len": ["error", { "code": 130 }],
"no-var": "error",
"semi": "error",
"no-multi-spaces": "error",
"space-in-parens": "error",
"no-multiple-empty-lines": "error",
"prefer-const": "error",
"no-use-before-define": "error"
}
}

4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

lint-staged
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"arrowParens": "avoid"
}
47 changes: 30 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
{
"name": "hackerrank",
"version": "1.0.0",
"description": "Solutions for HackerRank Problems in Javascript.",
"main": "index.js",
"scripts": {
"test": "mocha --recursive",
"report": "nyc mocha --recursive"
},
"author": "",
"license": "ISC",
"dependencies": {
"chai": "^4.2.0",
"mocha": "^6.2.1"
},
"devDependencies": {
"nyc": "^14.1.1"
}
"name": "hackerrank",
"version": "1.0.0",
"description": "Solutions for HackerRank Problems in Javascript.",
"main": "index.js",
"scripts": {
"test": "mocha --recursive",
"report": "nyc mocha --recursive",
"prepare": "husky install"
},
"lint-staged": {
"*.js": [
"npx pretty-quick --staged",
"eslint --fix"
]
},
"author": "",
"license": "ISC",
"dependencies": {
"chai": "^4.2.0",
"mocha": "^6.2.1"
},
"devDependencies": {
"eslint": "7.32.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-plugin-import": "2.24.2",
"husky": "7.0.2",
"lint-staged": "11.2.1",
"nyc": "^14.1.1",
"prettier": "2.4.1"
}
}
46 changes: 23 additions & 23 deletions test/Arrays/birthday-cake-candles.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
const birthdayCakeCandles = require("../../Arrays/birthday-cake-candles");
const { describe, it } = require("mocha");
const { expect } = require("chai");
const { describe, it } = require('mocha');
const { expect } = require('chai');
const birthdayCakeCandles = require('../../Arrays/birthday-cake-candles');

describe("Birthday Cake Candles", () => {
it("returns 0 for empty array", () => {
expect(birthdayCakeCandles([])).to.equal(0);
});
describe('Birthday Cake Candles', () => {
it('returns 0 for empty array', () => {
expect(birthdayCakeCandles([])).to.equal(0);
});

it("returns 1 if there is only one candle", () => {
expect(birthdayCakeCandles([1])).to.equal(1);
expect(birthdayCakeCandles([2])).to.equal(1);
expect(birthdayCakeCandles([3])).to.equal(1);
});
it('returns 1 if there is only one candle', () => {
expect(birthdayCakeCandles([1])).to.equal(1);
expect(birthdayCakeCandles([2])).to.equal(1);
expect(birthdayCakeCandles([3])).to.equal(1);
});

it("returns 2 if there are two candles with the same height", () => {
expect(birthdayCakeCandles([1, 1])).to.equal(2);
expect(birthdayCakeCandles([2, 2])).to.equal(2);
expect(birthdayCakeCandles([3, 3])).to.equal(2);
});
it('returns 2 if there are two candles with the same height', () => {
expect(birthdayCakeCandles([1, 1])).to.equal(2);
expect(birthdayCakeCandles([2, 2])).to.equal(2);
expect(birthdayCakeCandles([3, 3])).to.equal(2);
});

it("returns correct amount for array with different sized candles", () => {
expect(birthdayCakeCandles([3, 2, 1, 3])).to.equal(2);
expect(birthdayCakeCandles([3, 2, 1, 3, 4, 5, 4])).to.equal(1);
expect(birthdayCakeCandles([3, 2, 1, 1, 2, 2, 4, 4, 4])).to.equal(3);
expect(birthdayCakeCandles([3, 2, 1])).to.equal(1);
});
it('returns correct amount for array with different sized candles', () => {
expect(birthdayCakeCandles([3, 2, 1, 3])).to.equal(2);
expect(birthdayCakeCandles([3, 2, 1, 3, 4, 5, 4])).to.equal(1);
expect(birthdayCakeCandles([3, 2, 1, 1, 2, 2, 4, 4, 4])).to.equal(3);
expect(birthdayCakeCandles([3, 2, 1])).to.equal(1);
});
});