Skip to content

Commit

Permalink
CY-2720 - Final alignments for ESLint configuration (#38)
Browse files Browse the repository at this point in the history
* Turned off security/detect-non-literal-require rule as it is duplicated by import/no-dynamic-require
* Added eslint-common-node ESLint configuration
* Added prettier-common Prettier configuration for all UI projects
* Added env setup to common ESLint configs
* Moved ESLint and Prettier configuration files to configs directory
* Updated eslint* and prettier dependencies
* Fixed source code and tests after prettier version upgrade
* Aligned lint script in package.json files with other projects:
  * added --cache switch and added .eslintcache to .gitignore
  * added --ignore-path .gitignore
  * added --max-warnings 10

* Removed CircleCI from documentation and scripts
* Fixed security issues by updating dependencies
  • Loading branch information
qooban authored Oct 19, 2020
1 parent 1f2e9d8 commit 6dcf3ba
Show file tree
Hide file tree
Showing 16 changed files with 12,115 additions and 6,257 deletions.
12 changes: 2 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
{
"extends": [
"plugin:jsdoc/recommended",
"./eslint/eslint-common.json"
"./configs/eslint-common.json"
],
"rules": {
"jsdoc/require-jsdoc": ["error"]
},
"overrides": [
{
"files": "test/**/*.js",
"env": {
"jest": true
}
}
]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.eslintcache
.idea
dist
node_modules
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./configs/prettier-common.json');
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Cloudify UI Common

[![npm](https://img.shields.io/npm/v/cloudify-ui-common.svg?style=flat)](https://circleci.com/gh/cloudify-cosmo/cloudify-ui-common)
[![CircleCI](https://img.shields.io/circleci/project/github/cloudify-cosmo/cloudify-ui-common.svg?style=svg)](https://circleci.com/gh/cloudify-cosmo/cloudify-ui-common)
[![npm](https://img.shields.io/npm/v/cloudify-ui-common.svg?style=flat)](https://www.npmjs.com/package/cloudify-ui-common)
[![jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)

This repository contains common static assets (images, fonts, styles, etc.) as well as JS library with functions reusable across Cloudify UI applications.
Expand Down Expand Up @@ -73,7 +72,7 @@ There is [Cloudify Brandbook](https://drive.google.com/file/d/1KimyHFey_AoK2nKop

* [API](./src/README.md) - exposed JavaScript API

* [ESLint](./eslint/README.md) - shared common ESLint configs
* [Configurations](./configs/README.md) - shared development tools configuration files
* [Fonts](./fonts/README.md) - shared common fonts
* [Images](./images/README.md) - shared common images
* [Styles](./styles/README.md) - shared CSS, SCSS stylesheets
Expand Down Expand Up @@ -159,9 +158,9 @@ If you met all points from the checklist above, follow these steps:
* `npm run publish:minor` for new minor version,
* `npm run publish:major` for new major version,

which will create special branch, add commit to it containing version bump in `package*.json` files according to your choice, tag the commit and push branch to remote. That should trigger CircleCI jobs finalizing publish.
which will create special branch, add commit to it containing version bump in `package*.json` files according to your choice, tag the commit and push branch to remote. That should trigger Jenkins jobs finalizing publish.

1. Check if [cloudify-ui-common @ CircleCI](https://circleci.com/gh/cloudify-cosmo/cloudify-ui-common) jobs were successful.
1. Check if Jenkins jobs were successful.

1. Verify [cloudify-ui-common @ NPM](https://www.npmjs.com/package/cloudify-ui-common) was updated properly.

Expand Down
38 changes: 38 additions & 0 deletions configs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Configurations

This directory contains shared configuration for development tools.


### ESLint

ESLint configs should be extended by every cloudify-ui project/module.

#### Usage

Once `cloudify-ui-common` is installed as a dependency it is required to modify project's ESLint config (most probably `.eslintrc` or `.eslintrc.json` file) by adding the following entry (assuming ESLint config file is located in top level directory and it is a non-react project):
```json
{
"extends": ["./node_modules/cloudify-ui-common/configs/eslint-common.json"]
}
```
It is also required to install peer dependencies as specified in `package.json`.
There are three configuration files that can be extended.
The table below describes their purpose and dependencies necessary to be installed prior using each configuration file.

| Configuration file | Used for | Dependencies |
|--- |--- |---|
| `eslint-common.json` | non-react common projects | `eslint`, `eslint-config-prettier`, `eslint-plugin-import`, `eslint-plugin-prettier`, `eslint-plugin-scanjs-rules`, `eslint-plugin-security` |
| `eslint-common-react.json` | react-based projects | all from `eslint-common.json` and `eslint-plugin-react`, `eslint-plugin-react-hooks`, `eslint-plugin-jsx-a11y` |
| `eslint-common-node.json` | node-based projects | all from `eslint-common.json`, `eslint-plugin-node` |


### Prettier

Prettier config should be extended by every cloudify-ui project/module.

#### Usage

Once `cloudify-ui-common` is installed as a dependency it is required to modify project's Prettier config (you should use JS version - `.prettierrc.js` file) by requiring common configuration the following way:
```js
module.exports = require('./node_modules/cloudify-ui-common/configs/prettier-common.json');
```
9 changes: 9 additions & 0 deletions configs/eslint-common-node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"./eslint-common.json",
"plugin:node/recommended"
],
"env": {
"node": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"props": false
}
]
},
"env": {
"browser": true
}
}
1 change: 1 addition & 0 deletions eslint/eslint-common.json → configs/eslint-common.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"security/detect-new-buffer": "error",
"security/detect-no-csrf-before-method-override": "error",
"security/detect-non-literal-fs-filename": "off",
"security/detect-non-literal-require": "off",
"security/detect-object-injection": "off",
"security/detect-possible-timing-attacks": "error",
"security/detect-pseudoRandomBytes": "error",
Expand Down
4 changes: 3 additions & 1 deletion .prettierrc → configs/prettier-common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"printWidth": 120,
"singleQuote": true,
"endOfLine": "lf",
"tabWidth": 4
"tabWidth": 4,
"arrowParens": "avoid",
"trailingComma": "none"
}
18 changes: 0 additions & 18 deletions eslint/README.md

This file was deleted.

10 changes: 5 additions & 5 deletions jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pipeline {
yamlFile 'jenkins/build-pod.yaml'
}
}

environment {
MAIN_BRANCH = 'master'
WORKSPACE = "${env.WORKSPACE}"
Expand All @@ -36,7 +36,7 @@ pipeline {
dir("${env.WORKSPACE}/${env.PROJECT}") {
echo "Install dependencies"
sh 'npm ci --prefer-offline'

echo "Build application"
sh 'npm run build'

Expand Down Expand Up @@ -65,14 +65,14 @@ pipeline {
withVault([configuration: configuration, vaultSecrets: secrets]) {
echo "Authenticate with registry"
sh "echo '//registry.npmjs.org/:_authToken=${env.NPM_TOKEN}' > .npmrc"

echo "Publish package"
sh 'npm publish'

echo "Setup git user"
sh '''
git config user.email "[email protected]"
git config user.name "cosmo-admin-CircleCI"
git config user.name "cosmo-admin-Jenkins"
'''

echo "Update main branch"
Expand Down Expand Up @@ -105,4 +105,4 @@ pipeline {
}
}
}
}
}
Loading

0 comments on commit 6dcf3ba

Please sign in to comment.