Earl Fay

Earl Fay

1602148740

Improve Your Code With ESLint + VSCode + Airbnb Styleguide

In this video, we’ll set up ESLint to improve our code quality and style. We’ll integrate it with VSCode to make things super easy!

#eslint #vscode #javascript #web-development #programming

What is GEEK

Buddha Community

Improve Your Code With ESLint + VSCode + Airbnb Styleguide

Improve Your Code With ESLint + VsCode + Airbnb Styleguide

In this video, we’ll set up ESLint to improve our code quality and style. We’ll integrate it with VSCode to make things super easy!

Subscribe: https://www.youtube.com/channel/UCrqAGUPPMOdo0jfQ6grikZw

#eslint #vscode #airbnb

Earl Fay

Earl Fay

1602148740

Improve Your Code With ESLint + VSCode + Airbnb Styleguide

In this video, we’ll set up ESLint to improve our code quality and style. We’ll integrate it with VSCode to make things super easy!

#eslint #vscode #javascript #web-development #programming

Tyrique  Littel

Tyrique Littel

1604008800

Static Code Analysis: What It Is? How to Use It?

Static code analysis refers to the technique of approximating the runtime behavior of a program. In other words, it is the process of predicting the output of a program without actually executing it.

Lately, however, the term “Static Code Analysis” is more commonly used to refer to one of the applications of this technique rather than the technique itself — program comprehension — understanding the program and detecting issues in it (anything from syntax errors to type mismatches, performance hogs likely bugs, security loopholes, etc.). This is the usage we’d be referring to throughout this post.

“The refinement of techniques for the prompt discovery of error serves as well as any other as a hallmark of what we mean by science.”

  • J. Robert Oppenheimer

Outline

We cover a lot of ground in this post. The aim is to build an understanding of static code analysis and to equip you with the basic theory, and the right tools so that you can write analyzers on your own.

We start our journey with laying down the essential parts of the pipeline which a compiler follows to understand what a piece of code does. We learn where to tap points in this pipeline to plug in our analyzers and extract meaningful information. In the latter half, we get our feet wet, and write four such static analyzers, completely from scratch, in Python.

Note that although the ideas here are discussed in light of Python, static code analyzers across all programming languages are carved out along similar lines. We chose Python because of the availability of an easy to use ast module, and wide adoption of the language itself.

How does it all work?

Before a computer can finally “understand” and execute a piece of code, it goes through a series of complicated transformations:

static analysis workflow

As you can see in the diagram (go ahead, zoom it!), the static analyzers feed on the output of these stages. To be able to better understand the static analysis techniques, let’s look at each of these steps in some more detail:

Scanning

The first thing that a compiler does when trying to understand a piece of code is to break it down into smaller chunks, also known as tokens. Tokens are akin to what words are in a language.

A token might consist of either a single character, like (, or literals (like integers, strings, e.g., 7Bob, etc.), or reserved keywords of that language (e.g, def in Python). Characters which do not contribute towards the semantics of a program, like trailing whitespace, comments, etc. are often discarded by the scanner.

Python provides the tokenize module in its standard library to let you play around with tokens:

Python

1

import io

2

import tokenize

3

4

code = b"color = input('Enter your favourite color: ')"

5

6

for token in tokenize.tokenize(io.BytesIO(code).readline):

7

    print(token)

Python

1

TokenInfo(type=62 (ENCODING),  string='utf-8')

2

TokenInfo(type=1  (NAME),      string='color')

3

TokenInfo(type=54 (OP),        string='=')

4

TokenInfo(type=1  (NAME),      string='input')

5

TokenInfo(type=54 (OP),        string='(')

6

TokenInfo(type=3  (STRING),    string="'Enter your favourite color: '")

7

TokenInfo(type=54 (OP),        string=')')

8

TokenInfo(type=4  (NEWLINE),   string='')

9

TokenInfo(type=0  (ENDMARKER), string='')

(Note that for the sake of readability, I’ve omitted a few columns from the result above — metadata like starting index, ending index, a copy of the line on which a token occurs, etc.)

#code quality #code review #static analysis #static code analysis #code analysis #static analysis tools #code review tips #static code analyzer #static code analysis tool #static analyzer

Samanta  Moore

Samanta Moore

1621137960

Guidelines for Java Code Reviews

Get a jump-start on your next code review session with this list.

Having another pair of eyes scan your code is always useful and helps you spot mistakes before you break production. You need not be an expert to review someone’s code. Some experience with the programming language and a review checklist should help you get started. We’ve put together a list of things you should keep in mind when you’re reviewing Java code. Read on!

1. Follow Java Code Conventions

2. Replace Imperative Code With Lambdas and Streams

3. Beware of the NullPointerException

4. Directly Assigning References From Client Code to a Field

5. Handle Exceptions With Care

#java #code quality #java tutorial #code analysis #code reviews #code review tips #code analysis tools #java tutorial for beginners #java code review

Installing and using ESLint on your existing JavaScript code

Why linting? 🤔

Javascript is a great language, However, since it is flexible, there is a possibility of writing bad codes and to dig yourself into a hole. Javascript is a dynamic language and it’s loosely typed, which means that there’s a lot that can go wrong, so ESLint is very helpful as**it analyses your code without executing it**.

ESLint is a code quality tool whose job is to scan your project files and point out potential issues. The issues can be non-critical, such as formatting, or critical, such as trying to reference a function that does not exist.

Now, ESLint is not alone in this space, there are other tools like JSHint and JSLint. All of these tools try to solve the same problem, but in recent years, the community has started moving towards ESLint. This is because ESLint has been better at keeping up with the latest features from ES6 and ES7 while the other tools don’t have as great integrations so the community has started to shift away from them.

Installing & Setting up🎯

There are two ways by which you can install ESLint; globally or in your particular project. It’s easier to do it globally, but on the official webpage for ESLint, they recommend not to install it globally and that you should install it locally in each project and the main reason for this is that it makes it easier to collaborate with other developers on individual projects and have different rules(rules are the style conventions that you apply to the code). ESLint is a package, which we install using NPM.

For this tutorial, I’m using my existing project repository as a sample repository. The master branch will have the original code and I’ll use “linted” branch to install and lint code using ESLint. I’m assuming that you already have git and node installed on your system. I have cloned the repository on my system and switched the branch to “linted”.

Files before installing ESLint

Let’s install ESlint and save it as a developer dependency. We use ESLint as a developer dependency because the code of your project does not depend on the ESLint instead you want to use it while you’re developing your project and when you release the project it won’t need the ESLint.

npm install eslint --save-dev 

Once the installation is finished, open the package.json file and you will see the updated entry of ESLint under “devDependencies”.

#programming #eslint-configuration #eslint #airbnb #coding-style