The use of fctx.data().splitlines() means that the precommit hook will prevent you from making e.g. a one-line typo fix in a file which already had trailing whitespace before. Since it is not really acceptable in a project with a long history to mix formatting changes with bug fixes (lest you prevent hg annotate from working, introduce spurious merge conflicts, etc.), cleaning up unrelated lines in the file is not an option.
There should be an option to only scan those lines which form part of the diff. For a new file, all lines would be scanned.