Skip to content
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

[DEVEX-101] Update @pagopa/eslint-config #4

Merged
merged 21 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/perfect-coats-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pagopa/eslint-config": major
---

Updated configuration to match our current code style, switched to flat config file.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
15 changes: 15 additions & 0 deletions .github/workflows/code-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Code Review

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize]
paths:
- apps/**
- packages/**

jobs:
js_code_review:
uses: pagopa/dx/.github/workflows/js_code_review.yaml@c461016f071d813b2012c88674df41c753f56b16
name: Code Review
secrets: inherit
35 changes: 35 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Node.js environment
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 18
cache: "yarn"

- name: Install dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@aba318e9165b45b7948c60273e0b72fce0a64eb9 # v1.4.7
with:
version: yarn version
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@ override.tf.json
*.DS_Store
*.log
*.h2.db
settings.json
__TMP
.metals/
__azurite_*
/.idea
.bastianhost.ini
**/modules/**/.terraform.lock.hcl
**/_modules/**/.terraform.lock.hcl

# yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

dist
.env
node_modules
.turbo
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.12.2
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"esbenp.prettier-vscode"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
},
"prettier.prettierPath": ".yarn/sdks/prettier/index.cjs"
}
5 changes: 5 additions & 0 deletions .yarn/sdks/integrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is automatically generated by @yarnpkg/sdks.
# Manual changes might be lost!

integrations:
- vscode
20 changes: 20 additions & 0 deletions .yarn/sdks/prettier/bin/prettier.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require prettier/bin/prettier.cjs
require(absPnpApiPath).setup();
}
}

// Defer to the real prettier/bin/prettier.cjs your application uses
module.exports = absRequire(`prettier/bin/prettier.cjs`);
20 changes: 20 additions & 0 deletions .yarn/sdks/prettier/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require prettier
require(absPnpApiPath).setup();
}
}

// Defer to the real prettier your application uses
module.exports = absRequire(`prettier`);
7 changes: 7 additions & 0 deletions .yarn/sdks/prettier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "prettier",
"version": "3.2.5-sdk",
"main": "./index.cjs",
"type": "commonjs",
"bin": "./bin/prettier.cjs"
}
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packageExtensions:
"eslint-plugin-perfectionist@*":
dependencies:
"@typescript-eslint/types": "*"
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DevEx repository for shared tools and pipelines.

- [DX](#dx)
- [GitHub Action Templates](#github-action-templates)
- [infra\_plan.yaml](#infra_planyaml)
- [infra_plan.yaml](#infra_planyaml)
- [What it does](#what-it-does)
- [Example](#example)
- [Requirements](#requirements)
Expand Down Expand Up @@ -70,3 +70,90 @@ This module helps to create the necessary infrastructure to run GitHub Actions o
This module creates a Container App Job on an existing Container App Environment. It requires your repository name as input, in order to create a trigger on the GitHub Actions status of that repository. Moreover, it has a dependencies on a KeyVault where it creates a read-only access policy to access secrets.

N.B. If you are adding a new Container App Job, it is likely that your repository must be added to GITHUB PAT access scope. Ask for this one-time operation to `engineering-team-cloud-eng` team.

## NPM packages

This project requires specific versions of the following tools. To make sure your development setup matches with production follow the recommended installation methods.

- **Node.js**

Use [nodenv](https://github.com/nodenv/nodenv) to install the [required version](.node-version) of `Node.js`.

```sh
nodenv install
node --version
```

- **Yarn**

Yarn must be installed using [Corepack](https://yarnpkg.com/getting-started/install), included by default in `Node.js`.

```sh
corepack enable
yarn --version
```

- **Terraform**

Use [tfenv](https://github.com/tfutils/tfenv) to install the [required version](.terraform-version) of `terraform`.

```sh
tfenv install
terraform version
```

- **pre-commit**

[Follow the official documentation](https://pre-commit.com/) to install `pre-commit` in your machine.

```sh
pre-commit install
```

## Tasks

Tasks are defined in the `turbo.json` and `package.json` files. To execute a task, just run the command at the project root:

```sh
yarn <cmd>
```

`Turborepo` will execute the task for all the workspaces that declare the same command in their `package.json` file; it also applies caching policies to the command according to the rules defined in `turbo.json`.

To define a new task:

- add the definition to `turbo.json` under `pipeline`;
- add a script with the same name in `package.json` as `turbo <cmd name>`.

To see the defined task run `yarn run`

## Dependencies

> [!IMPORTANT]
> This project uses Yarn Plug'n'Play as installation strategy for dependencies. [Check out](https://yarnpkg.com/features/pnp) the official Yarn documentation to lean about pnp and its difference from the classic `node_modules` approach.

```sh
# install all dependencies for the project
yarn

# install a dependency to a workspace
# (workspace name is the name in the package.json file)
yarn workspace <workspace name> add <package name>
yarn workspace <workspace name> add -D <package name>

# install a dependency for the monorepo
# (ideally a shared dev dependency)
yarn add -D <package name>
```

To add a dependency to a local workspace, manually edit the target workspace's `package.json` file adding the dependency as

```json
"dependencies": {
"my-dependency-workspace": "workspace:*"
}
```

### Yarn SDKS (.yarn/sdks)

Smart IDEs (such as VSCode or IntelliJ) require special configuration for TypeScript to work when using Plug'n'Play installs. That configuration is generated automatically by `yarn` (via `yarn dlx @yarnpkg/sdks vscode vim [other-editor...]`) and commited to `.yarn/sdks`.
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@pagopa/dx",
"packageManager": "[email protected]",
"workspaces": [
"packages/**"
],
"devDependencies": {
"prettier": "3.2.5",
"turbo": "^1.13.2"
},
"scripts": {
"code-review": "turbo run typecheck format:check lint:check",
"version": "yarn changeset version && yarn --mode update-lockfile",
"release": "yarn build && changeset publish"
},
"dependencies": {
"@changesets/cli": "^2.27.1"
}
}
1 change: 1 addition & 0 deletions packages/eslint-config/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
36 changes: 36 additions & 0 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# @pagopa/eslint-config

This package provides PagoPA's `eslint.config.js` as an extensible shared config.

## Usage

> [!IMPORTANT]
> This config requires `eslint >= 9.0`, so it uses flat config files. Learn more about ESLint 9 and flat config files in the [official documentation](https://eslint.org/docs/latest/use/configure/configuration-files).

1. Install `eslint` and `@pagopa/eslint-config`

```shell
yarn add -D eslint @pagopa/eslint-config
```

2. Create a file names `eslint.config.js` at the root of your workspace with the following content

> [!TIP]
> If your workspace uses CommonJS, name this file `eslint.config.mjs`

```js
import pagopa from "@pagopa/eslint-config";

export default [...pagopa];
```

3. Add `lint` and `lint:check` scripts in your `package.json`

```json
{
"scripts": {
"lint": "eslint --fix src",
"lint:check": "eslint src"
}
}
```
15 changes: 15 additions & 0 deletions packages/eslint-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import perfectionist from "eslint-plugin-perfectionist/configs/recommended-natural";

export default [
{
languageOptions: {
ecmaVersion: 2023,
sourceType: "module",
},
},
js.configs.recommended,
prettier,
perfectionist,
];
Loading