@endosome/eslint-config-googleappsscript
v1.0.1
Published
Shared ESLint 10 flat config for Google Apps Script projects, built on @endosome/eslint-config-node
Maintainers
Readme
@endosome/eslint-config-googleappsscript
A shared ESLint flat config for Google Apps Script
projects, written in TypeScript or JavaScript (for example with clasp). It is
@endosome/eslint-config-node with the changes below, so a Node.js
project and an Apps Script project share one set of rules. ESLint 10 only.
Requirements
- ESLint
^10.0.0 - Node.js
>=22.18.0 - TypeScript
>=4.8.4 <6.1.0(typescript-eslint does not support TypeScript 7 yet)
Usage
npm install --save-dev eslint typescript @endosome/eslint-config-googleappsscript// eslint.config.js
export { default } from '@endosome/eslint-config-googleappsscript';The export is an array of flat config objects, so project rules go after it:
import config from '@endosome/eslint-config-googleappsscript';
export default [...config, { ignores: ['src/**/*.js'] }];See the README of @endosome/eslint-config-node for everything that is inherited (plugins, type-aware linting, the
rules that differ from the earlier ESLint 8 config).
What is different from the Node.js config
| | |
|---|---|
| Top-level declarations are never "unused" | Google calls menu handlers, triggers and web app entry points by name. @typescript-eslint/no-unused-vars skips variables, functions and imports at the top level of a file (vars: 'local') and still reports unused variables inside functions. Parameters, caught errors, destructured array items and variables that start with _ are ignored. |
| TypeScript files are CommonJS scripts | sourceType: 'commonjs', so the top level of a file is not a module scope, whatever "type" the package.json has. |
| Modules provided by the build resolve | import-x/no-unresolved ignores bare specifiers that start with a capital letter, such as import { x } from 'GoogleSpreadsheets'. npm package names cannot have capitals, so those are modules the build supplies. Other missing modules are still reported. |
| HTML sidebars and dialogs are linted as browser scripts | .html files get the same rules (no n/*, vars: 'local') and sourceType: 'script', so a function that the markup calls from onclick is not "unused". |
| No Node.js rules | The n/* rules are off, and the Node.js globals (process, require, setTimeout, URL, ...) are not defined. |
| JavaScript files are scripts | sourceType: 'script' and no-undef with the Apps Script globals: the services (SpreadsheetApp, GmailApp, Logger, Utilities, ...), console and the advanced services. TypeScript is checked by tsc instead. |
| No module-only rules | unicorn/prefer-module and unicorn/prefer-top-level-await are off. |
Things to know
- Unused imports are not reported. The same
vars: 'local'setting that lets entry points pass also skips imports at the top level. UsetscwithnoUnusedLocalsif you want to catch those. - A project override of
@typescript-eslint/no-unused-varsreplaces these options. If a project sets the rule itself, repeatvars: 'local':['error', { vars: 'local', argsIgnorePattern: '^_', varsIgnorePattern: '^_' }]. .gsfiles are not linted, only.js,.tsand their variants (clasp 3 uploads.js).- Generated JavaScript next to the TypeScript sources (for example from a build step) is linted like any other
file; add it to
ignores.
Globals
globals.js lists the global variables that @types/google-apps-script declares. It is generated by
npm run generate, and a test fails when it is out of date with the installed types.
License
MIT.
