Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

ttsukagoshi/gas-github

Repository files navigation

Google Apps Script ユーザのための Super Linter 設定ファイルサンプル

GitHub Super-Linter

Super Linter とは

GitHub が作成した、各種言語の linter を GitHub Actions として実行できるもの。Push 時や Pull Request 時などをトリガーとする。(公式資料はこちら)。

使い方

フォルダ.githubを、丸ごと自分が作業しているレポジトリにコピーする。

各種エラーへの対応

ESLint が吐き出すエラーの詳細はこちらを参照のこと。

GAS でよくあること。

  • メニューからの呼び出しなどで使っている関数がno-unused-varsエラーとなってしまう。
  • 逆に、他ファイルで定義した関数がno-undefエラーとして引っかかる場合がある。

例えば、スプレッドシートを開いた時に実行する関数として

function myFunction() {
  let test = 'variable';
  console.log(test.length);
}

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('test')
    .addItem('これを実行', 'myFunction')
    .addToUi();
}

というスクリプトを用意すると、'myFunction' is defined but never used と怒られるので、あらかじめファイルの冒頭に

/* exported myFunction, myFunction2, ... */

と入力することでエラーを回避できる。 また、別ファイルで定義済みの関数や変数について'LocalizedMessage' is not definedと怒られるようなときは、同じくスクリプトファイル冒頭に

/* global LocalizedMessage, global-var1, global-var2, ... */

と入力することでエラーを回避できる。

なお、GAS 固有のクラス(SpreadsheetApp, GmailAppなどなど)で、よく使うものは.eslintrc.yml内のglobalsにてあらかじめ定義している。必要に応じて、追記する。

clasp 設定メモ

  1. clasp clone "***********"
  2. .clasp.jsonに 1 行追加"rootDir": "./src"
  3. mkdir srcからのmv appsscript.json src
  4. npm init
  5. npm install -D @google/clasp
  6. npm install -D typescript @types/google-apps-script
  7. npm install -D eslint prettier eslint-config-prettier eslint-plugin-prettier
  8. npm install -D @typescript-eslint/eslint-plugin @typescript-eslint/parser

About

claspを活用した、GitHub上でのGoogle Apps Script(GAS)開発。手順とサンプルファイル集。

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks