上QQ阅读APP看书,第一时间看更新
Linting our code
Now, let's run eslint on our src/index.js to discover problems with our code:
$ npx eslint src/index.js
/home/dli/.d4nyll/.beja/final/code/6/src/index.js
1:8 error Strings must use singlequote quotes
2:1 error Expected 1 empty line after import statement not followed by another import import/newline-after-import
3:24 warning Unexpected unnamed function func-names
4:22 error A space is required after '{' object-curly-spacing
4:51 error A space is required before '}' object-curly-spacing
6:2 error Missing semicolon semi
8:21 error Newline required at end of file but not found eol-last
8 problems (7 errors, 1 warning)
6 errors and 0 warnings potentially fixable with the `--fix` option.
Follow the instructions and fix those issues, or pass the --fix flag to have ESLint fix the issues for you automatically. At the end, you should end up with a file that looks like this:
import '@babel/polyfill';
import http from 'http';
function requestHandler(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!');
}
const server = http.createServer(requestHandler);
server.listen(8080); // Note that there is a newline below this line