npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-config-imart

v2.2.7

Published

Definition of ESLint rules and intra-mart JavaScript API

Downloads

34

Readme

eslint-config-imart

CircleCI npm LICENSE

intra-mart開発のためのESLint設定

本リポジトリについて

ルール

valid-jsdoc, require-jsdoc

JSDocを記述することを強制します。本ルールでは、各関数について以下の記載を求めます。

  • 関数についての説明
  • すべての名前付き引数の型(順番も含めて正しいこと)
  • 戻り値の型

特に、何も返さない関数についても戻り値の型を記載する必要があります。JavaScriptはreturnに遭遇しなかった場合やreturn文に何も与えなかった場合、undefinedを返却するため、次のように記載すると正しいと判定されます。

  • @returns {void}
  • @returns {undefined}

引数および戻り値の説明については、型名や変数名から自明な場合は必要ありません。そうでない場合は記載してください。

strict

strictモードを使用します。Strict モード - JavaScript | MDN

使い方

このルール定義はESLint Shareable Configsの仕組みで提供されています。

インストール

npm i -D eslint eslint-config-airbnb-base eslint-plugin-import eslint-config-imart

See: eslint-config-airbnb-base

ルール定義

プロジェクトのルートディレクトリに.eslintrcファイルを以下のように作成します。

{
  "root": true,
  "extends": [
    "airbnb-base/legacy",
    "imart",
    "prettier"
  ],
  "globals": {
    "require": false
  }
}

実行

./node_modules/.bin/eslint .

eslintrc

intra-mart API定義

ESLintでは、未定義のグローバルオブジェクトへの参照はエラーとなります。したがって、intra-martのAPIオブジェクトはすべてglobalsとして定義される必要があります。

このプロジェクトでは、intra-mart APIのグローバル定義ファイルを提供しています。

必要に応じてextendsとして利用してください。

{
  "extends": [
    "airbnb-base/legacy",
    "imart",
    "imart/globals/iap-server-core",
    "imart/globals/iap-client-core",
    "prettier"
  ]
}

ファイル名のルールは以下の通りです。

${platform}-${environment}-${app}

それぞれの変数間を-で繋ぎ、各変数内の単語区切りには_を使います。すべて小文字です。

どのようなAPI定義があるかはglobalsディレクトリを参照してください。

ES6

node.jsモジュールを書く場合等、ES6の機能が必要な場合はairbnb-baseを利用してください。

{
  "extends": [
    "airbnb-base",
    "imart",
    "prettier"
  ],
}

ルールの階層構造

ESLintでは、.eslintrcをlint対象ファイルの位置からファイルシステムを上へ再帰的に適用します: Configuration Cascading and Hierarchy

よって、各プロジェクトに配置する.eslintrcは次のようになっているべきです:

$PROJECT_HOME/.eslintrc

{
  "root": true,
  "extends": [
    "airbnb-base",
    "imart",
    "prettier"
  ]
}

$PROJECT_HOME/src/main/jssp/.eslintrc

{
  "extends": ["imart/globals/iap-server-core"]
}

$PROJECT_HOME/src/main/public/.eslintrc

{
  "extends": ["imart/globals/iap-client-core"]
}

これにより、ルール定義は共通のまま、サーバサイドJSではサーバ側のAPIのみ、クライアントサイドJSではクライアント側のAPIのみが定義されている状態になります。

メンテナンスについて

テスト

ルールのリリース前には、必ずテストを実行してください:

npm test

修正に関する議論

あるルールを変更する場合、本リポジトリのissueにて議論を行ってください。

定義済みコマンド

npm runを実行すると、実行可能なコマンドが一覧表示されます。

現時点では以下のコマンドが実行可能です。

  • npm test: ルールについてのテストを実行します
  • npm run build: intra-mart APIのグローバル定義を生成します

FAQ

unused警告について

init関数、action関数などjavascriptファイル内から直接呼ばれない関数/変数は、no-unused-varsオプションによって未使用の警告が出ます。これを回避するため、eslintに該当変数が他で利用されていることをexportedディレクティブで通知する必要があります。

/* exported init */
function init(request) {
    // code
}

※注: "env": { "node": true }の環境下ではexportedは機能ません。node.jsでは変数は常にスクリプトローカルであるためです。