PowerShell / PowerShell/PSScriptAnalyzer

Rule Proposal: Warn on dot-sourced function

オープン
#696 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Issue - New Rule
主要言語
C#
スター
2.2k
フォーク
414
平均マージ
13時間 1分
マージ済み PR(30日)
2

説明

I've inherited a project where everything is in, for lack of a better description, undeclared global scope, spread across several files. Functions don't have always have parameters, and are called with a dot before the function name. Variables are treated as global, though not declared. For example:

c:\Utils.ps1

function Write-MyLog {
$itemToLog | out-file c:\mylog.txt -append
}


c:\Interface.ps1

. c:\Utils.ps1

$itemToLog = "Something happened"
. Write-MyLog


Miraculously, this all works. Of course, I dare not change anything.

I would love it if ". Write-MyLog" came up as a warning, and even more so if there were some indication that "$itemToLog" in C:\Interface.ps1 was being used by the function called from c:\Utils.ps1.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、サンプルスクリプト c:\Utils.ps1 と c:\Interface.ps1 での動作を再現し、dot-sourced 関数呼び出しと、ファイルをまたぐ $itemToLog 変数に注目します。完了とは、アナライザーが要求された構造について警告し、変数の使用状況について要求された情報を提供し、スコープと想定される診断が合意されていることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
powershell
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。