Skip to content

Commit 6cf6ba3

Browse files
committed
build(javascript): reconfigure linting
1 parent 122f9c2 commit 6cf6ba3

File tree

10 files changed

+4403
-0
lines changed

10 files changed

+4403
-0
lines changed

.github/workflows/lint.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# GitHub Action: Lint JavaScript code
2+
#
3+
# This workflow lints the JavaScript code in the repository.
4+
#
5+
# Maintainer: Matt Norris <matnorri@cisco.com>
6+
#
7+
# Usage:
8+
# - Lints the JavaScript code in the repository.
9+
# - Fails the workflow if any linting issues are found.
10+
#
11+
# For more information on ESLint, see: https://eslint.org/
12+
# For more information on Prettier, see: https://prettier.io/
13+
14+
name: Lint JavaScript
15+
on:
16+
workflow_dispatch:
17+
pull_request:
18+
types: [opened, reopened, synchronize]
19+
paths:
20+
- 'packages/javascript/**/*.js'
21+
- 'packages/javascript/**/*.json'
22+
- '.github/workflows/lint.yml'
23+
24+
jobs:
25+
lint:
26+
runs-on: ubuntu-latest
27+
defaults:
28+
run:
29+
working-directory: packages/javascript
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version-file: '.nvmrc'
38+
cache: 'npm'
39+
cache-dependency-path: packages/javascript/package-lock.json
40+
41+
- name: Install dependencies
42+
run: npm ci
43+
44+
- name: Run ESLint
45+
run: npm run lint:eslint
46+
47+
- name: Run Prettier
48+
run: npm run lint:prettier

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/jod

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Makefile
2+
# description: Build, lint, and run tasks for the essentials project
3+
# author: Matt Norris <matnorri@cisco.com>
4+
5+
.PHONY: help lint-javascript lint-js install-javascript install-js
6+
7+
# Default target - show help
8+
help:
9+
@echo "Available targets:"
10+
@echo " lint-javascript (lint-js) - Lint JavaScript packages"
11+
@echo " install-javascript (install-js) - Install JavaScript dependencies"
12+
@echo " help - Show this help message"
13+
14+
# Lint JavaScript packages
15+
lint-javascript: lint-js
16+
lint-js:
17+
@echo "Linting JavaScript packages..."
18+
@cd packages/javascript && npm run lint
19+
20+
# Install JavaScript dependencies
21+
install-javascript: install-js
22+
install-js:
23+
@echo "Installing JavaScript dependencies..."
24+
@cd packages/javascript && npm install

docs/NEXTJS_SETUP.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Next.js ESLint Configuration
2+
3+
This document describes the Next.js ESLint plugin that was removed from the JavaScript packages configuration, and how to restore it when adding a Next.js application.
4+
5+
## What Was Removed
6+
7+
The Next.js ESLint plugin was removed because the current packages are Node.js libraries/packages, not Next.js applications. The plugin requires a `pages/` or `src/pages/` directory for Next.js routing, which doesn't exist in library packages.
8+
9+
### Removed from `package.json`
10+
11+
```json
12+
"devDependencies": {
13+
"@next/eslint-plugin-next": "^12.1.6"
14+
}
15+
```
16+
17+
### Removed from `.eslintrc.json`
18+
19+
```json
20+
"extends": [
21+
"plugin:@next/next/recommended"
22+
]
23+
```
24+
25+
## Why It Was Removed
26+
27+
- The `@next/next` ESLint plugin is specifically for Next.js React applications
28+
- It includes rules like `no-html-link-for-pages` that check for proper Link usage in Next.js
29+
- These rules require a Next.js pages directory structure
30+
- Without a Next.js app, the plugin generates errors like:
31+
```
32+
Pages directory cannot be found at .../pages or .../src/pages
33+
```
34+
35+
## How to Restore for Next.js Apps
36+
37+
When you add a Next.js application to this directory, follow these steps:
38+
39+
### 1. Install the Next.js ESLint Plugin
40+
41+
```bash
42+
cd packages/javascript
43+
npm install --save-dev @next/eslint-plugin-next
44+
```
45+
46+
Or use a specific version:
47+
48+
```bash
49+
npm install --save-dev @next/eslint-plugin-next@^12.1.6
50+
```
51+
52+
### 2. Update `.eslintrc.json`
53+
54+
Add the Next.js plugin back to the extends array:
55+
56+
```json
57+
{
58+
"extends": [
59+
"eslint:recommended",
60+
"plugin:import/errors",
61+
"plugin:import/warnings",
62+
"plugin:sonarjs/recommended",
63+
"prettier",
64+
"plugin:@next/next/recommended"
65+
]
66+
}
67+
```
68+
69+
### 3. Next.js-Specific Configuration
70+
71+
If you need to customize the Next.js ESLint rules, you can add them to the rules section:
72+
73+
```json
74+
{
75+
"rules": {
76+
"@next/next/no-html-link-for-pages": ["error", "path/to/your/pages/"],
77+
"@next/next/no-img-element": "error",
78+
"@next/next/no-page-custom-font": "warn"
79+
}
80+
}
81+
```
82+
83+
### 4. Consider Separate ESLint Configs
84+
85+
For a monorepo with both Node.js packages and Next.js apps, consider:
86+
87+
**Option A: Separate Config Files**
88+
- Keep the current `.eslintrc.json` for Node.js packages
89+
- Create a separate `.eslintrc.json` in your Next.js app directory with the Next.js plugin
90+
91+
**Option B: ESLint Overrides**
92+
Use overrides in the main `.eslintrc.json`:
93+
94+
```json
95+
{
96+
"extends": [
97+
"eslint:recommended",
98+
"plugin:import/errors",
99+
"plugin:import/warnings",
100+
"plugin:sonarjs/recommended",
101+
"prettier"
102+
],
103+
"overrides": [
104+
{
105+
"files": ["nextjs-app/**/*.{js,jsx,ts,tsx}"],
106+
"extends": ["plugin:@next/next/recommended"]
107+
}
108+
]
109+
}
110+
```
111+
112+
## Next.js ESLint Rules
113+
114+
The `@next/next/recommended` config includes rules for:
115+
116+
- **Link usage**: Ensures proper use of Next.js `<Link>` components
117+
- **Image optimization**: Enforces use of `next/image` instead of `<img>`
118+
- **Font optimization**: Checks for proper font loading
119+
- **Script optimization**: Validates `next/script` usage
120+
- **Document structure**: Ensures proper `_document.js` setup
121+
- **Head component**: Validates Next.js `<Head>` usage
122+
123+
## Additional Resources
124+
125+
- [Next.js ESLint Documentation](https://nextjs.org/docs/basic-features/eslint)
126+
- [Next.js ESLint Plugin on npm](https://www.npmjs.com/package/@next/eslint-plugin-next)
127+
- [Next.js ESLint Config](https://nextjs.org/docs/app/building-your-application/configuring/eslint)
128+
129+
## Date Removed
130+
131+
- **Date**: October 6, 2025
132+
- **Reason**: No Next.js applications in current package structure
133+
- **Affected Files**: `package.json`, `.eslintrc.json`

packages/javascript/.eslintrc.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:import/errors",
11+
"plugin:import/warnings",
12+
"plugin:sonarjs/recommended",
13+
"prettier"
14+
],
15+
"parser": "@babel/eslint-parser",
16+
"parserOptions": {
17+
"ecmaVersion": 2021,
18+
"requireConfigFile": false,
19+
"babelOptions": {
20+
"presets": ["@babel/preset-react"]
21+
}
22+
},
23+
"ignorePatterns": ["docs", "output", "node_modules", "coverage", "dist", "*.lock"],
24+
"rules": {},
25+
"overrides": [
26+
{
27+
"files": ["*.json"],
28+
"rules": {
29+
"semi": "off"
30+
}
31+
}
32+
]
33+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Dependencies
2+
node_modules/
3+
package-lock.json
4+
5+
# Build outputs
6+
dist/
7+
build/
8+
coverage/
9+
output/
10+
11+
# Logs
12+
*.log
13+
14+
# Documentation
15+
docs/
16+
17+
# Lerna
18+
lerna-debug.log
19+
20+
# Changelogs
21+
CHANGELOG.md
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": false,
5+
"printWidth": 80,
6+
"tabWidth": 2,
7+
"useTabs": false
8+
}

packages/javascript/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# JavaScript Packages
2+
3+
This directory contains JavaScript/Node.js packages for essential tools and utilities.
4+
5+
## Packages
6+
7+
- **@cisco/analytics** - Analytics events and constants to track system usage
8+
- **@cisco/bot-commands** - Create responsive bot commands with ease
9+
- **@cisco/bot-factory** - Create Webex bots
10+
- **@cisco/bot-middleware** - Middleware to intercept messages
11+
- **@cisco/cards** - Create Adaptive Cards and rich messages
12+
- **@cisco/core** - Helpful functions to reduce parsing and errors
13+
- **@cisco/docs-docusaurus** - Docusaurus config and utilities
14+
- **@cisco/google** - Utilities to work with Google Cloud
15+
- **@cisco/releases** - Release management tools
16+
- **@cisco/salesforce** - Salesforce integration utilities
17+
18+
## Development
19+
20+
### Prerequisites
21+
22+
- Node.js (version specified in `.nvmrc` at the project root)
23+
- npm
24+
25+
### Linting
26+
27+
This project uses ESLint and Prettier to maintain code quality and consistency.
28+
29+
#### Install Dependencies
30+
31+
```bash
32+
cd packages/javascript
33+
npm install
34+
```
35+
36+
#### Run Linting
37+
38+
To check for linting issues:
39+
40+
```bash
41+
# Run both ESLint and Prettier checks
42+
npm run lint
43+
44+
# Run only ESLint
45+
npm run lint:eslint
46+
47+
# Run only Prettier
48+
npm run lint:prettier
49+
```
50+
51+
#### Linting Configuration
52+
53+
- **ESLint**: Configuration in `.eslintrc.json`
54+
- Extends recommended rules plus import, sonarjs, and prettier configs
55+
- Supports CommonJS and ES2021
56+
- Configured for Node.js and Jest environments
57+
58+
- **Prettier**: Configuration in `.prettierrc.json`
59+
- 2-space indentation
60+
- Semicolons required
61+
- 80 character line width
62+
63+
#### GitHub Actions
64+
65+
Linting runs automatically on:
66+
- Pull requests affecting JavaScript files
67+
- Pushes to `main` and `turborepo` branches
68+
- Manual workflow dispatch
69+
70+
The workflow file is located at `.github/workflows/lint.yml`.
71+
72+
## License
73+
74+
[Apache 2.0](https://choosealicense.com/licenses/apache-2.0/)

0 commit comments

Comments
 (0)