Skip to content

Feature/eslint #831

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

Merged
merged 37 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7028300
Integrate EsLint + Prettier
jason-fox Nov 30, 2019
206886c
Add CNR
jason-fox Nov 30, 2019
a5334ea
Fixing test expectations
jason-fox Nov 30, 2019
e4df205
Fixing test expectations
jason-fox Nov 30, 2019
433dd6c
Merge commit 'd9c5ac9af583e7610eaafa5baa0f4abb1aead5c2' into feature/…
jason-fox Dec 4, 2019
7bf4d03
Merge commit '25b690aa97059ba3e2306f300ca3647486134c18' into feature/…
jason-fox Dec 15, 2019
cd9475a
Add editorconfig
jason-fox Dec 21, 2019
cbe8e4d
Update coding guidelines to include eslint and editorconfig
jason-fox Dec 21, 2019
876ca4b
Amending text
jason-fox Dec 21, 2019
0bd74e7
Capitalize ESLint
jason-fox Dec 21, 2019
5e839d9
Update .editorconfig
jason-fox Jan 9, 2020
325aaab
Merge branch 'master' into feature/eslint
jason-fox Jan 13, 2020
288a22e
Merge branch 'master' into feature/eslint
jason-fox Jan 16, 2020
4820c76
Remove package lock.
jason-fox Jan 16, 2020
61bcd0a
Merge branch 'master' into feature/eslint
jason-fox Jan 16, 2020
9f261d9
Merge branch 'master' into feature/eslint
jason-fox Feb 26, 2020
fe6f3dc
Re-add CNR
jason-fox Feb 26, 2020
113b4ac
Merge commit '2f6509ba67eca09486161092fcef9ab0430f75a3' into feature/…
jason-fox Jun 22, 2020
14e64a0
Remove package lock
jason-fox Jun 22, 2020
ee7b6a0
Merge commit '4519d15018205914941decac4bc44ae2f2bc6c73' into feature/…
jason-fox Jun 26, 2020
20868dd
Merge branch 'master' into feature/eslint
jason-fox Jul 6, 2020
c35b0ba
Fix broken test from merge
jason-fox Jul 17, 2020
818d8a1
Merge branch 'master' into feature/eslint
jason-fox Sep 10, 2020
c0a6b96
Run prettier, fix docs.
jason-fox Sep 10, 2020
05ebe3f
Merge branch 'master' into feature/eslint
jason-fox Sep 11, 2020
c7e663c
Merge commit 'master' into feature/eslint
jason-fox Sep 15, 2020
e96a17c
Merge branch 'master' into feature/eslint
jason-fox Sep 18, 2020
bdc61e1
Merge branch 'master' into feature/eslint
jason-fox Oct 6, 2020
aabb4ea
Merge branch 'master' into feature/eslint
jason-fox Oct 7, 2020
8de0be2
Increase timeout
jason-fox Oct 7, 2020
32e84af
Merge 'master' into feature/eslint
jason-fox Oct 27, 2020
dfce339
Merge branch 'master' into feature/eslint
jason-fox Oct 27, 2020
6b4c511
Merge commit 'master' into feature/eslint
jason-fox Nov 2, 2020
924c3a9
Merge branch 'master' into feature/eslint
jason-fox Nov 16, 2020
68cebf8
Update CHANGES_NEXT_RELEASE
jason-fox Nov 18, 2020
ae4416e
Fix typo
jason-fox Nov 18, 2020
ea6d399
Update documentation.
jason-fox Nov 18, 2020
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
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# editorconfig.org
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true

[*.{json,yml,md,babelrc,eslintrc,remarkrc}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.{js}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "tamia",
"parserOptions": {
"sourceType": "module"
},
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-shadow": 0,
Copy link
Member

@fgalan fgalan Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing with the .eslintrc.json file in IOTA-JSON .eslintrc.json repo, this setting has been added here.

Which effect does it have in the eslint rules?

Copy link
Contributor Author

@jason-fox jason-fox Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reasoning it was added here - the latest version of eslint complains about Telefonica style callbacks in the code (it wants the callback variable name to be unique) hence the shadowed variable name rule must be dropped. This is only due to the updates to a more modern Eslint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

So, I understand that "no-shadow": 0 is the desired setting and the repos not using it (if any) should be fixed. Out of the scope of this PR, of course.

NTC

"valid-jsdoc": 0
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
.project
.metadata
npm-debug.log
.eslintcache

31 changes: 0 additions & 31 deletions .jshintrc

This file was deleted.

9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"singleQuote": true,
"parser": "flow",
"printWidth": 120,
"trailingComma": "none",
"tabWidth": 4
}
7 changes: 7 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Update codebase to use ES6
- Remove JSHint and jshint overrides
- Add esLint using standard tamia presets
- Replace var with let/const
- Fix or disable eslint errors
Add prettier code formatting
Add husky and lint-staged
141 changes: 58 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@
[![Coverage Status](https://coveralls.io/repos/github/telefonicaid/iotagent-node-lib/badge.svg?branch=master)](https://coveralls.io/github/telefonicaid/iotagent-node-lib?branch=master)
![Status](https://nexus.lab.fiware.org/static/badges/statuses/iot-node-lib.svg)

This project aims to provide a Node.js module to enable IoT Agent developers to
build custom agents for their devices that can easily connect to NGSI Context
Brokers (such as [Orion](https://github.com/telefonicaid/fiware-orion)).

An IoT Agent is a component that lets groups of devices send their data to and
be managed from a FIWARE NGSI Context Broker using their own native protocols.
IoT Agents should also be able to deal with security aspects of the FIWARE
platform (authentication and authorization of the channel) and provide other
common services to the device programmer.

This project is part of [FIWARE](https://www.fiware.org/). For more information
check the FIWARE Catalogue entry for the
This project aims to provide a Node.js module to enable IoT Agent developers to build custom agents for their devices
that can easily connect to NGSI Context Brokers (such as [Orion](https://github.com/telefonicaid/fiware-orion)).

An IoT Agent is a component that lets groups of devices send their data to and be managed from a FIWARE NGSI Context
Broker using their own native protocols. IoT Agents should also be able to deal with security aspects of the FIWARE
platform (authentication and authorization of the channel) and provide other common services to the device programmer.

This project is part of [FIWARE](https://www.fiware.org/). For more information check the FIWARE Catalogue entry for the
[IoT Agents](https://github.com/Fiware/catalogue/tree/master/iot-agents).

| :books: [Documentation](https://iotagent-node-lib.rtfd.io) | :mortar_board: [Academy](https://fiware-academy.readthedocs.io/en/latest/iot-agents/idas) | :dart: [Roadmap](https://github.com/telefonicaid/iotagent-node-lib/blob/master/docs/roadmap.md) |
|---|---|---|
| ---------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |


## Index

Expand Down Expand Up @@ -59,7 +56,6 @@ functionality provided by the IoT Agent node lin (e.g. for contecting to a conex
its device communications using a common vocabulary regardless of the payload, syntax or transport protocol used by the
device itself.


## Install

The **IoT Agent node library** is not a standalone product and should be added as a dependency to `package.json` of the
Expand All @@ -78,43 +74,39 @@ In order to use the library within your own IoT Agent, you must first you requir
const iotagentLib = require("iotagent-node-lib");
```

Information about how to configure the Library can be found at the corresponding
section of the
Information about how to configure the Library can be found at the corresponding section of the
[Installation & Administration Guide](doc/installationguide.md).

## Usage

This library has no packaging or build processes. The [Getting Started](doc/getting-started.md) is a good place to start.
Usage of the library is explained in the [User & Programmers Manual](doc/usermanual.md).
This library has no packaging or build processes. The [Getting Started](doc/getting-started.md) is a good place to
start. Usage of the library is explained in the [User & Programmers Manual](doc/usermanual.md).

- Details of the architecture of an IoT Agent be found [here](doc/architecture.md).
- Further Advanced topics can be found [here](doc/advanced-topics.md).
- The following features are listed as [deprecated](doc/deprecated.md).
- Details of the architecture of an IoT Agent be found [here](doc/architecture.md).
- Further Advanced topics can be found [here](doc/advanced-topics.md).
- The following features are listed as [deprecated](doc/deprecated.md).

## API

The **IoT Agent node library** offers a simple REST API which provides common functionality to access, provision and
decommission devices.
[API](doc/api.md).
decommission devices. [API](doc/api.md).

## Testing


Contributions to development can be found [here](doc/development.md) - additional contributions are welcome.

### Agent Console

A command-line client to experiment with the library is packed with it. The
command-line client can be started using the following command:
A command-line client to experiment with the library is packed with it. The command-line client can be started using the
following command:

```console
bin/agentConsole.js
```

The client offers an API similar to the one offered by the library: it can start
and stop an IoT agent, register and unregister devices, send measures mimicking
the device and receive updates of the device data. Take into account that, by
default, the console uses the same `config.js` file than the IoT Agent.
The client offers an API similar to the one offered by the library: it can start and stop an IoT agent, register and
unregister devices, send measures mimicking the device and receive updates of the device data. Take into account that,
by default, the console uses the same `config.js` file than the IoT Agent.

The command-line client creates a console that offers the following options:

Expand Down Expand Up @@ -172,24 +164,20 @@ listdevices

#### Command-line testing

The library also offers a Context Broker and IoT Agent client that can be used
to:
The library also offers a Context Broker and IoT Agent client that can be used to:

- Simulate operations to the Context Broker used by the IoT Agent, triggering
Context Provider forwardings for lazy attributes and checking the
appropriate values for active ones.
- Simulate operations to the Device Provisioning API and Configuration API of
the IoT Agent.
- Simulate operations to the Context Broker used by the IoT Agent, triggering Context Provider forwardings for lazy
attributes and checking the appropriate values for active ones.
- Simulate operations to the Device Provisioning API and Configuration API of the IoT Agent.

The tester can be started with the following command, from the root folder of
the project:
The tester can be started with the following command, from the root folder of the project:

```console
bin/iotAgentTester.js
```

From the command-line, the `help` command can be used to show a description of
the currently supported features. These are the following:
From the command-line, the `help` command can be used to show a description of the currently supported features. These
are the following:

```text
stressInit
Expand Down Expand Up @@ -304,30 +292,26 @@ migrate <targetDb> <service> <subservice>
subservices, use the "*" value.
```

The agent session stores transient configuration data about the target Context
Broker and the target IoT Agent. This configuration is independent, and can be
checked with the `showConfigCb` and `showConfigIot` commands, respectively.
Their values can be changed with the `configCb` and `configIot` commands
respectively. The new configurations will be deleted upon startup.
The agent session stores transient configuration data about the target Context Broker and the target IoT Agent. This
configuration is independent, and can be checked with the `showConfigCb` and `showConfigIot` commands, respectively.
Their values can be changed with the `configCb` and `configIot` commands respectively. The new configurations will be
deleted upon startup.

#### Creating specialized testers

The command-line testing tools make use of the
[command-node Node.js library](https://github.com/telefonicaid/command-shell-lib)
for command-line utils. In order to help creating testing tools for IoTAgents of
specific protocols, all the commands of the library tester are offered as a
array that can be directly imported into other Command-Line tools, using the
following steps:
[command-node Node.js library](https://github.com/telefonicaid/command-shell-lib) for command-line utils. In order to
help creating testing tools for IoTAgents of specific protocols, all the commands of the library tester are offered as a
array that can be directly imported into other Command-Line tools, using the following steps:

- Require the `iotagent-node-lib` command-line module in your command-line
tool:
- Require the `iotagent-node-lib` command-line module in your command-line tool:

```javascript
var iotaCommands = require('iotagent-node-lib').commandLine;
var iotaCommands = require("iotagent-node-lib").commandLine;
```

- Initialize the command-line utils (the initialization function takes two
arguments, that will be explained in detail below:
- Initialize the command-line utils (the initialization function takes two arguments, that will be explained in detail
below:

```javascript
iotaCommands.init(configCb, configIot);
Expand All @@ -342,56 +326,47 @@ commands = commands.concat(commands, iotaCommands.commands);
- Execute the command-line interpreter as usual:

```javascript
clUtils.initialize(commandLine.commands, 'IoT Agent tester> ');
clUtils.initialize(commandLine.commands, "IoT Agent tester> ");
```

The command-line module makes use of two configuration objects. Both can be
shown and edited in the command-line using the provided commands, but a default
value must be present.
The command-line module makes use of two configuration objects. Both can be shown and edited in the command-line using
the provided commands, but a default value must be present.

The Context Broker configuration object holds all the information about the
Context Broker where the IoT Agent to be tested is connected. It MUST contain
the following attributes:
The Context Broker configuration object holds all the information about the Context Broker where the IoT Agent to be
tested is connected. It MUST contain the following attributes:

- **host**: host where the Context Broker instance is located.
- **port**: port where the Context Broker instance is listening.
- **service**: service that will be used in all the NGSI operations.
- **subservice**: service that will be used in all the NGSI operations.

The IoT Agent configuration object holds information about the IoT Agent that is
being tested. It MUST contain the following attributes:
The IoT Agent configuration object holds information about the IoT Agent that is being tested. It MUST contain the
following attributes:

- **host**: host where the IoT Agent instance is located.
- **port**: port where the IoT Agent instance is listening.
- **service**: service that will be used to group devices and device
information.
- **subservice**: subservice that will be used to group devices and device
information.
- **service**: service that will be used to group devices and device information.
- **subservice**: subservice that will be used to group devices and device information.

---

## Licence

The IoT Agent Node Library is licensed under [Affero General Public License (GPL)
version 3](./LICENSE).
The IoT Agent Node Library is licensed under [Affero General Public License (GPL) version 3](./LICENSE).

© 2019 Telefonica Investigación y Desarrollo, S.A.U



### Are there any legal issues with AGPL 3.0? Is it safe for me to use?

There is absolutely no problem in using a product licensed under AGPL 3.0. Issues with GPL
(or AGPL) licenses are mostly related with the fact that different people assign different
interpretations on the meaning of the term “derivate work” used in these licenses. Due to this,
some people believe that there is a risk in just _using_ software under GPL or AGPL licenses
(even without _modifying_ it).
There is absolutely no problem in using a product licensed under AGPL 3.0. Issues with GPL (or AGPL) licenses are mostly
related with the fact that different people assign different interpretations on the meaning of the term “derivate work”
used in these licenses. Due to this, some people believe that there is a risk in just _using_ software under GPL or AGPL
licenses (even without _modifying_ it).

For the avoidance of doubt, the owners of this software licensed under an AGPL-3.0 license
wish to make a clarifying public statement as follows:

> Please note that software derived as a result of modifying the source code of this
> software in order to fix a bug or incorporate enhancements is considered a derivative
> work of the product. Software that merely uses or aggregates (i.e. links to) an otherwise
> unmodified version of existing software is not considered a derivative work, and therefore
> it does not need to be released as under the same license, or even released as open source.
> Please note that software derived as a result of modifying the source code of this software in order to fix a bug or
> incorporate enhancements is considered a derivative work of the product. Software that merely uses or aggregates (i.e.
> links to) an otherwise unmodified version of existing software is not considered a derivative work, and therefore it
> does not need to be released as under the same license, or even released as open source.
Loading