@labnol/js-config
v3.0.0
Published
Shareable ESLint flat config and Prettier config for Google Apps Script, Node.js and React projects, ready for ESLint 10, Vite and Tailwind CSS
Maintainers
Readme
@labnol/js-config
Shared ESLint and Prettier settings for Google Apps Script, Node and React projects. Pick the preset that matches your project and set up each tool with a single line.
Built by Amit Agarwal for Digital Inspiration, where it is used in popular projects like Mail Merge, Document Studio and labnol.org.
What's Included
| Preset | Use it for | What it adds |
| ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------ |
| eslint/appsscript | Google Apps Script projects | Apps Script globals such as SpreadsheetApp, plus google.script.run and OAuth libraries |
| eslint/node | Node.js projects | Node globals and a warning for import cycles |
| eslint/react | React apps built with Vite | React, Hooks, React Compiler and Fast Refresh rules |
| prettier | Any project | 120-character lines, single quotes, semicolons and LF line endings |
| prettier/tailwind | Projects that use Tailwind CSS | The same style, plus sorted Tailwind classes |
Every ESLint preset is an ESLint 10 flat config. It requires ===, blocks nested ternaries, else after return and reassigned parameters, and warns on default exports outside tool configs such as vite.config.js. It sorts imports, lints JSON files, sorts keys in JSON other than package.json, appsscript.json, tsconfig*.json, jsconfig*.json, .clasp.json and .vscode/*.json, and leaves formatting to Prettier.
Install
npm install -D @labnol/js-configThis also installs ESLint, Prettier and the ESLint plugins the presets import, so remove them from the project's own devDependencies. npm links the eslint and prettier commands into the project, so npm run lint works without listing them. pnpm and Yarn don't, so with those, add eslint and prettier to the project too.
Requires Node ^20.19.0, ^22.13.0, or >=24, the same range as ESLint 10.
React Projects
A React project also needs the React plugins and the TypeScript runtime used by @eslint-react/eslint-plugin (even when your source is JavaScript):
npm install -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh typescriptFor Tailwind class sorting, install its optional Prettier plugin separately:
npm install -D prettier-plugin-tailwindcssNo peer-dependency bypass is needed. Remove legacy-peer-deps=true from your project's .npmrc if you added it for an earlier version of this package.
Set up ESLint
Create eslint.config.mjs in the project root with one line. The .mjs extension works in both CommonJS and ESM projects:
export { default } from '@labnol/js-config/eslint/appsscript';Change appsscript to node for a Node project or react for a React project.
Override a Rule
To change a rule in one project, import the preset and add your overrides after it:
import appsScript from '@labnol/js-config/eslint/appsscript';
export default [...appsScript, { rules: { 'no-console': 'off' } }];Node Code in an Apps Script Project
The Apps Script preset has no Node globals, because Apps Script has no process, Buffer, fetch or setTimeout. Tool configs such as vite.config.js still get them. For other code that runs in Node, such as tests, scripts or Cloud Functions, add the globals for those folders:
import appsScript from '@labnol/js-config/eslint/appsscript';
import globals from 'globals';
export default [
...appsScript,
{ files: ['scripts/**/*.js', '**/*.test.js'], languageOptions: { globals: globals.node } },
];Apps Script Entry Points
The default Apps Script preset supports bundled ESM source. For files deployed directly to Apps Script, use script mode and declare functions called by triggers, custom menus, or google.script.run with an exported comment:
import appsScript from '@labnol/js-config/eslint/appsscript';
export default [...appsScript, { files: ['Code.js'], languageOptions: { sourceType: 'script' } }];In Code.js:
/* exported onOpen, doGet */
function onOpen() {
SpreadsheetApp.getUi();
}
function doGet() {
return HtmlService.createHtmlOutput('Hello');
}List your own callable functions in the comment and adjust the file pattern to match your script files. Unused local variables and unlisted functions are still checked. The exported comment only applies in script mode; bundled modules should use normal JavaScript exports.
Apps Script source has Apps Script globals, while *.config.js, *.config.mjs, and *.config.cjs files have Node globals. Node-only APIs such as process and Buffer are reported in Apps Script source.
React Version
The React preset targets React 19. For a React 18 app, set the version after the preset:
import react from '@labnol/js-config/eslint/react';
export default [...react, { settings: { 'react-x': { version: '18' } } }];React rules apply to JavaScript and JSX files, leaving JSON to the JSON rules. Browser source does not include Node's process global; use Vite's import.meta.env for environment variables. Tool configuration files retain Node globals.
Migrating from 1.x or 2.x
Version 3 replaces the React lint plugin and changes several rule names. Remove eslint-plugin-react from your project (npm uninstall eslint-plugin-react), replace it with @eslint-react/eslint-plugin and install typescript using the React install command above. Remove the old eslint-plugin-react entry from overrides if your project added it for ESLint 10 compatibility. The official Hooks, Compiler, and Fast Refresh plugins remain in use.
Update project-specific overrides to the new rule names:
| Previous rule | Replacement |
| ----------------------------------------- | ----------------------------------------------- |
| react/jsx-key | @eslint-react/no-missing-key |
| react/no-array-index-key | @eslint-react/no-array-index-key |
| react/no-unstable-nested-components | @eslint-react/no-nested-component-definitions |
| react/jsx-no-constructed-context-values | @eslint-react/no-unstable-context-value |
| react/hook-use-state | @eslint-react/use-state |
| react/button-has-type | @eslint-react/dom-no-missing-button-type |
The new recommended React checks differ from the old plugin's checks. Function declarations and arrow functions are both accepted as components. The old JSX style rules (boolean props, curly braces, fragments, and self-closing tags) are no longer enforced by this preset. Change React version overrides from settings.react.version to settings['react-x'].version.
For projects upgrading from 1.x, the Apps Script preset rejects Node-only globals in application source. Mark directly deployed script entry points as described above. CommonJS .cjs files retain CommonJS parsing, including top-level returns.
Set up Prettier
Delete the project's .prettierrc and add one line to package.json:
"prettier": "@labnol/js-config/prettier"For a project that uses Tailwind, add /tailwind to the end. Prettier then also sorts the Tailwind classes in your markup:
"prettier": "@labnol/js-config/prettier/tailwind"This needs prettier-plugin-tailwindcss in the project, which the Install step covers.
Development Checks
npm ci
npm test
npm run lint
npm run format:check
npm run test:consumer -- npmThe consumer check packs the package, installs it outside the repository, and verifies all five public exports and CLI access. It checks a minimal install without optional plugins and a full install with React and Tailwind. It needs network access to install dependencies and removes its temporary projects afterward.
Use npm run test:consumer -- pnpm or npm run test:consumer -- yarn to test pnpm or Yarn Classic. Install the corresponding package manager first. CI runs unit checks across Node 20.19, 22.13, 24, and 26, and consumer checks with npm, pnpm 10, and Yarn Classic on Node 24.
Publish an Update
Commit your change, then run:
npm version patchUse
patchfor a fix,minorfor a new rule, ormajorfor a change that flags existing code. The command runs the tests and the linter, bumps the version and pushes the commit and tag to GitHub. The tag starts a GitHub Action that publishes the new version to npm within a few minutes.In each project, install the new version:
npm install -D @labnol/js-config@latest
