Skip to content

Commit

Permalink
style: adopt eslint styling
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierGeerinck committed Oct 25, 2021
1 parent fe5f0c7 commit f7f4f59
Show file tree
Hide file tree
Showing 43 changed files with 3,197 additions and 1,434 deletions.
9 changes: 9 additions & 0 deletions .eslintignore
@@ -0,0 +1,9 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
build
dist
# don't lint nyc coverage output
coverage
# don't lint proto files and output
proto
19 changes: 19 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,19 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true,
"amd": true,
"node": true
},
"rules": {
"@typescript-eslint/ban-ts-comment": "off"
}
}
98 changes: 98 additions & 0 deletions daprdocs/content/en/js-sdk-contributing/js-contributing.md
Expand Up @@ -8,6 +8,104 @@ description: Guidelines for contributing to the Dapr JavaScript SDK

When contributing to the [JavaScript SDK](https://github.com/dapr/js-sdk) the following rules and best-practices should be followed.

## Commit Guidelines

The Dapr Javascript SDK uses the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
specification. The automatic changelog tool uses these to automatically generate
a changelog based on the commit messages. Here's a guide to writing a commit message
to allow this:

### Format

```
type(scope)!: subject
```

- `type`: the type of the commit is one of the following:

- `feat`: new features.
- `fix`: bug fixes.
- `docs`: documentation changes.
- `refactor`: refactor of a particular code section without introducing
new features or bug fixes.
- `style`: code style improvements.
- `perf`: performance improvements.
- `test`: changes to the test suite.
- `ci`: changes to the CI system.
- `build`: changes to the build system (we don't yet have one so this shouldn't apply).
- `chore`: for other changes that don't match previous types. This doesn't appear
in the changelog.

- `scope`: section of the codebase that the commit makes changes to. If it makes changes to
many sections, or if no section in particular is modified, leave blank without the parentheses.
Examples:

- Commit that adds a `test`:
```
test(actors): add an actor test
```

- Commit that changes many things at once:
```
style: adopt eslint
```

For changes to examples, the scope should be the example name with the `examples/` prefix:

-`fix(agnoster): commit subject`
-`fix(examples/http/actor): commit subject`

- `!`: this goes after the `scope` (or the `type` if scope is empty), to indicate that the commit
introduces breaking changes.

Optionally, you can specify a message that the changelog tool will display to the user to indicate
what's changed and what they can do to deal with it. You can use multiple lines to type this message;
the changelog parser will keep reading until the end of the commit message or until it finds an empty
line.

Example (made up):

```
style(agnoster)!: change dirty git repo glyph
BREAKING CHANGE: the glyph to indicate when a git repository is dirty has
changed from a Powerline character to a standard UTF-8 emoji.
Fixes #420
Co-authored-by: Username <email>
```

- `subject`: a brief description of the changes. This will be displayed in the changelog. If you need
to specify other details you can use the commit body but it won't be visible.

Formatting tricks: the commit subject may contain:

- Links to related issues or PRs by writing `#issue`. This will be highlighted by the changelog tool:
```
feat(archlinux): add support for aura AUR helper (#9467)
```

- Formatted inline code by using backticks: the text inbetween backticks will also be highlighted by
the changelog tool:
```
feat(shell-proxy): enable unexported `DEFAULT_PROXY` setting (#9774)
```

### Style

Try to keep the first commit line short. This is harder to do using this commit style but try to be
concise and if you need more space, you can use the commit body. Try to make sure that the commit
subject is clear and precise enough that users will know what change by just looking at the changelog.

## Coding Rules

To ensure consistency throughout the source code, keep these rules in mind as you are working:

* All features or bug fixes **must be tested** by one or more specs (unit-tests).
* All public API methods **must be documented**.
* We follow [ESLint RecommendedRules][https://eslint.org/docs/rules/].

## Examples

The `examples` directory contains code samples for users to run to try out specific functionality of the various JavaScript SDK packages and extensions. When writing new and updated samples keep in mind:
Expand Down
3 changes: 3 additions & 0 deletions documentation/development.md
Expand Up @@ -37,6 +37,9 @@ Tests are written per protocol layer: http or grpc. This is done because Dapr re
# Ports: 1883 = TCP MQTT Port | 8081 = HTTP API | 8083 = MQTT/SSL Port | 8883 = MQTT/Websocket/SSL Port | 8084 = MQTT/Websocket Port | 18083 = Dashboard
docker run -d --rm --name emqx -p 1883:1883 -p 8081:8081 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx

# Run Unit Tests
npm run test:unit

# Start gRPC tests
npm run test:e2e:grpc:main

Expand Down
20 changes: 10 additions & 10 deletions examples/http/actor-parking-sensor/src/ParkingSensorImpl.ts
Expand Up @@ -60,21 +60,21 @@ export default class ParkingSensorImpl extends AbstractActor implements ParkingS
}

generateRandomPoint(center: { lat: number, lng: number }, radius: number) {
var x0 = center.lng;
var y0 = center.lat;
const x0 = center.lng;
const y0 = center.lat;

// Convert Radius from meters to degrees.
var rd = radius / 111300;
const rd = radius / 111300;

var u = Math.random();
var v = Math.random();
const u = Math.random();
const v = Math.random();

var w = rd * Math.sqrt(u);
var t = 2 * Math.PI * v;
var x = w * Math.cos(t);
var y = w * Math.sin(t);
const w = rd * Math.sqrt(u);
const t = 2 * Math.PI * v;
const x = w * Math.cos(t);
const y = w * Math.sin(t);

var xp = x / Math.cos(y0);
const xp = x / Math.cos(y0);

// Resulting point.
return { 'lat': y + y0, 'lng': xp + x0 };
Expand Down
3 changes: 2 additions & 1 deletion examples/http/actor-parking-sensor/src/index.ts
Expand Up @@ -37,7 +37,8 @@ async function start() {
console.log("Waiting 10 seconds before starting");
await sleep(10000);

while (true) {
const isRunning = true;
while (isRunning) {
console.log("Simulating cars entering and leaving for 5% of the population");

const populationSize = Math.floor(amount * 0.05);
Expand Down
14 changes: 7 additions & 7 deletions examples/http/actor/src/actor/DemoActorCounterImpl.ts
Expand Up @@ -2,13 +2,13 @@ import { AbstractActor } from "dapr-client";
import DemoActorCounterInterface from "./DemoActorCounterInterface";

export default class DemoActorCounterImpl extends AbstractActor implements DemoActorCounterInterface {
counter: number = 0;
counter = 0;

async count(): Promise<void> {
this.counter++;
}
async count(): Promise<void> {
this.counter++;
}

async countBy(amount: number): Promise<void> {
this.counter += amount;
}
async countBy(amount: number): Promise<void> {
this.counter += amount;
}
}
17 changes: 8 additions & 9 deletions examples/http/actor/src/actor/DemoActorReminderImpl.ts
@@ -1,14 +1,13 @@
import { AbstractActor } from "dapr-client";
import DemoActorReminderInterface from "./DemoActorReminderInterface";

export default class DemoActorReminderImpl extends AbstractActor implements DemoActorReminderInterface {
counter: number = 0;
export default class DemoActorReminderImpl extends AbstractActor {
counter = 0;

async count(): Promise<void> {
this.counter++;
}
async count(): Promise<void> {
this.counter++;
}

async countBy(amount: number): Promise<void> {
this.counter += amount;
}
async countBy(amount: number): Promise<void> {
this.counter += amount;
}
}
2 changes: 0 additions & 2 deletions examples/http/actor/src/actor/DemoActorReminderInterface.ts

This file was deleted.

20 changes: 10 additions & 10 deletions examples/http/actor/src/actor/DemoActorTimerImpl.ts
Expand Up @@ -2,17 +2,17 @@ import { AbstractActor } from "dapr-client";
import DemoActorTimerInterface from "./DemoActorTimerInterface";

export default class DemoActorTimerImpl extends AbstractActor implements DemoActorTimerInterface {
counter: number = 0;
counter = 0;

async init(): Promise<string> {
return "Actor Activated";
}
async init(): Promise<string> {
return "Actor Activated";
}

async count(): Promise<void> {
this.counter++;
}
async count(): Promise<void> {
this.counter++;
}

async countBy(amount: number): Promise<void> {
this.counter += amount;
}
async countBy(amount: number): Promise<void> {
this.counter += amount;
}
}

0 comments on commit f7f4f59

Please sign in to comment.