Skip to content

Commit 68dd7cc

Browse files
authored
change eslint+airbnb to semistandard (#24)
* change eslint+airbnb to semistandard * fix linting errors * submissions/kissik/port-sniffer: Fix linting errors
1 parent f22af65 commit 68dd7cc

11 files changed

Lines changed: 355 additions & 181 deletions

File tree

CODE_QUALITY.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
### Code Quality Requirements for Homeworks
22

3-
The code submitted to this repository is required to be formatted with [Prettier](https://github.com/prettier/prettier) (for config details see "prettier" section in `package.json`) and match [Airbnb code style](https://github.com/airbnb/javascript).
4-
5-
Install and use [yarn](https://yarnpkg.com/en/docs/install)
6-
instead of `npm`.
3+
The code submitted to this repository is required to match [JavaScript Standard Style](https://standardjs.com/).
74

85
Please follow these steps:
9-
1. After cloning this repository install the dependencies (run `yarn` in project directory). This will install the following tools:
10-
- eslint
11-
- eslint-config-airbnb-base
12-
- prettier
13-
- eslint-config-prettier
14-
- eslint-plugin-prettier
6+
1. After cloning this repository install the dependencies (run `npm install` or `yarn` in project directory). This will install the following tools:
7+
- [semistandard](https://github.com/standard/semistandard) - JavaAscript Standard style guide, linter and formatted, plus semicolon requirement
158

16-
1. Install plugins for ESLint and Prettier for your code editor. Additionally you can enable "formatOnSave" option in your code editor, so that Prettier plugin will format your code every time you save a file.
9+
1. Install plugins for Semistandard code style for your code editor. Here is an [example for VSCode](https://marketplace.visualstudio.com/items?itemName=flet.vscode-semistandard). Additionally you can enable "formatOnSave" option in your code editor, so that Standard plugin will format your code every time you save a file.
1710

18-
1. Before submitting the PR run `yarn run lint:js` and fix errors (if any).
11+
1. Before submitting the PR run `npm run lint:js --fix` or `yarn run lint:js --fix`. This will check your code and fix all auto-fixable errors like missing semicolons or spaces. After that fix the remaining errors (if any).
1912

20-
1. This repository also enables ESLint change on pre-commit hook, so you should not be able to commit any code not conforming to ESLint rules.
13+
1. This repository also enables Standard check on pre-commit hook, so you should not be able to commit any code not conforming to ESLint rules.
2114

2215
1. Make sure your files end with an empty line.
2316
Most of the IDEs are capable of doing this for you.

package.json

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"lint:js": "eslint ./submissions --ignore-pattern **/node_modules/**",
8+
"lint:js": "semistandard \"submissions/**/*.js\"",
99
"lint-staged": "lint-staged",
1010
"install:void": ":",
1111
"install:kissik/port-sniffer": "cd ./submissions/kissik/port-sniffer && yarn",
@@ -23,40 +23,18 @@
2323
},
2424
"homepage": "https://github.com/kottans/nodejs-2019-homeworks#readme",
2525
"devDependencies": {
26-
"eslint": "^6.5.0",
27-
"eslint-config-airbnb-base": "^14.0.0",
28-
"eslint-config-prettier": "^6.3.0",
29-
"eslint-plugin-import": "^2.18.2",
30-
"eslint-plugin-prettier": "^3.1.1",
3126
"lint-staged": "^9.4.0",
3227
"npm-run-all": "^4.1.5",
3328
"pre-commit": "^1.2.2",
34-
"prettier": "1.18.2"
35-
},
36-
"eslintConfig": {
37-
"env": {
38-
"node": true,
39-
"es6": true
40-
},
41-
"extends": [
42-
"airbnb-base",
43-
"prettier"
44-
],
45-
"parserOptions": {
46-
"ecmaVersion": 2018,
47-
"sourceType": "script"
48-
},
49-
"plugins": ["prettier"],
50-
"rules": {
51-
"prettier/prettier": "error"
52-
}
53-
},
54-
"prettier": {
55-
"semi": true,
56-
"singleQuote": true
29+
"semistandard": "^14.2.0"
5730
},
5831
"pre-commit": "lint-staged",
5932
"lint-staged": {
60-
"*.js": "eslint"
33+
"*.js": "semistandard"
34+
},
35+
"semistandard": {
36+
"ignore": [
37+
"**/node_modules/**"
38+
]
6139
}
6240
}

submissions/Zakkarat/port-sniffer/sniffer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ const connectTo = async (host, port) => {
8383
});
8484
client.on('timeout', () => {
8585
client.destroy();
86-
reject();
86+
reject(new Error('Timeout'));
8787
});
8888
client.on('error', () => {
8989
client.destroy();
90-
reject();
90+
reject(new Error('Unknown error'));
9191
});
9292
client.connect({
9393
port,
@@ -122,7 +122,7 @@ const sniff = async ({ host, port, helped }) => {
122122
const openPorts = await checkConnection(hostPort);
123123
return openPorts.length
124124
? console.log(`\n${openPorts.join(', ')} ports are opened`)
125-
: console.log(`No ports opened`);
125+
: console.log('No ports opened');
126126
};
127127

128128
sniff(

submissions/eoneoff/data-structures-http/data_structures/linkedList.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
const { Node } = require('./node');
55

66
module.exports.LinkedList = class LinkedList {
7-
constructor() {
7+
constructor () {
88
this._root = null;
99
this._length = 0;
1010
}
1111

12-
*[Symbol.iterator]() {
12+
* [Symbol.iterator] () {
1313
let current = this._root;
1414
while (current) {
1515
yield current;
1616
current = current.next;
1717
}
1818
}
1919

20-
insert(value, successor = null) {
20+
insert (value, successor = null) {
2121
if (successor && this._root.value !== successor) {
2222
for (const node of this) {
2323
if (node.next && node.next.value === successor) {
@@ -33,7 +33,7 @@ module.exports.LinkedList = class LinkedList {
3333
}
3434
}
3535

36-
remove(value) {
36+
remove (value) {
3737
if (this._root.value === value) {
3838
this._root = this._root.next;
3939
this._length--;
@@ -49,11 +49,11 @@ module.exports.LinkedList = class LinkedList {
4949
}
5050
}
5151

52-
showList() {
52+
showList () {
5353
return Array.from(this, node => node.value);
5454
}
5555

56-
get length() {
56+
get length () {
5757
return this._length;
5858
}
5959
};
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/* eslint-disable no-underscore-dangle */
22
module.exports.Node = class Node {
3-
constructor(value, next) {
3+
constructor (value, next) {
44
this._value = value;
55
this._next = next;
66
}
77

8-
get value() {
8+
get value () {
99
return this._value;
1010
}
1111

12-
set value(value) {
12+
set value (value) {
1313
this._value = value;
1414
}
1515

16-
get next() {
16+
get next () {
1717
return this._next;
1818
}
1919

20-
set next(next) {
20+
set next (next) {
2121
this._next = next;
2222
}
2323
};

submissions/eoneoff/data-structures-http/data_structures/stack.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
const { Node } = require('./node');
44

55
module.exports.Stack = class Stack {
6-
constructor() {
6+
constructor () {
77
this._root = null;
88
this._length = 0;
99
}
1010

11-
push(value) {
11+
push (value) {
1212
this._root = new Node(value, this._root);
1313
this._length++;
1414
}
1515

16-
pop() {
16+
pop () {
1717
let out = null;
1818
if (this._length) {
1919
out = this._root.value;
@@ -23,7 +23,7 @@ module.exports.Stack = class Stack {
2323
return out;
2424
}
2525

26-
get length() {
26+
get length () {
2727
return this._length;
2828
}
2929
};

submissions/eoneoff/data-structures-http/server/handler.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
/* eslint-disable func-names */
44

5-
function isValidType(value) {
5+
function isValidType (value) {
66
return typeof value === 'string' || typeof value === 'number';
77
}
88

9-
function isJson(request) {
9+
function isJson (request) {
1010
return request.headers['content-type'] === 'application/json';
1111
}
1212

13-
function postStack(response, stack, data) {
13+
function postStack (response, stack, data) {
1414
stack.push(data.data);
1515
response.writeHead(200);
1616
response.end();
1717
}
1818

19-
function deleteStack(response, stack) {
19+
function deleteStack (response, stack) {
2020
response.writeHead(200);
2121
response.end(JSON.stringify({ data: stack.pop() }), {
2222
'Content-Type': 'application/json'
2323
});
2424
}
2525

26-
function getList(response, list) {
26+
function getList (response, list) {
2727
response.writeHead(200, { 'Content-Type': 'application/json' });
2828
response.end(JSON.stringify({ data: list.showList() }));
2929
}
3030

31-
function postList(response, list, data) {
31+
function postList (response, list, data) {
3232
if (!data.successor || isValidType(data.successor)) {
3333
try {
3434
list.insert(data.data, data.successor);
@@ -42,7 +42,7 @@ function postList(response, list, data) {
4242
response.end();
4343
}
4444

45-
function deleteList(response, list, data) {
45+
function deleteList (response, list, data) {
4646
try {
4747
list.remove(data.data);
4848
response.writeHead(200);
@@ -53,22 +53,22 @@ function deleteList(response, list, data) {
5353
}
5454
}
5555

56-
function notFound(response) {
56+
function notFound (response) {
5757
response.writeHead(404, 'Url not found');
5858
response.end();
5959
}
6060

61-
function wrongDataType(response) {
61+
function wrongDataType (response) {
6262
response.writeHead(400, 'Wrong data type');
6363
response.end();
6464
}
6565

66-
function wrongContentType(response) {
66+
function wrongContentType (response) {
6767
response.writeHead(400, 'Wrong content type');
6868
response.end();
6969
}
7070

71-
function handleListOperation(request, response, list, data) {
71+
function handleListOperation (request, response, list, data) {
7272
switch (request.method) {
7373
case 'POST':
7474
postList(response, list, data);
@@ -79,7 +79,7 @@ function handleListOperation(request, response, list, data) {
7979
}
8080
}
8181

82-
function handleJsonRequest(
82+
function handleJsonRequest (
8383
request,
8484
response,
8585
stack,
@@ -107,7 +107,7 @@ function handleJsonRequest(
107107
}
108108

109109
module.exports.dataHandler = (stack, list) => {
110-
return function(request, response) {
110+
return function (request, response) {
111111
const structureType = request.url.split('/')[1];
112112
if (request.method === 'GET' && structureType === 'list') {
113113
getList(response, list);

submissions/eoneoff/data-structures-http/server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ const http = require('http');
33
const { dataHandler } = require('./handler');
44

55
module.exports.Server = class Server {
6-
constructor(stack, list) {
6+
constructor (stack, list) {
77
this._stack = stack;
88
this._list = list;
99
this._server = http.createServer(dataHandler(this._stack, this._list));
1010
}
1111

12-
run(port = 8000, host = 'localhost') {
12+
run (port = 8000, host = 'localhost') {
1313
this._server.listen(port, host);
1414
}
1515
};

0 commit comments

Comments
 (0)