Commit Graph

44 Commits

Author SHA1 Message Date
Max Radermacher
c05511413a
Stop fixing license headers 2026-03-26 19:21:14 -05:00
Sasha Weiss
45f63da0ec
Introduce swiftformat 2025-12-19 14:36:47 -08:00
Sasha Weiss
efe9e73005
Add "contact message" Backup integration tests 2024-09-10 10:49:15 -07:00
Max Radermacher
82bb803d58
Inline MobileCoinMinimal 2024-04-25 16:35:47 -05:00
Max Radermacher
74e66ecba2
Clean up precommit.py 2024-04-15 14:02:27 -05:00
Max Radermacher
e73c56575b
Fix escape sequences in precommit.py 2024-01-09 09:48:18 -06:00
Max Radermacher
38236e9f8f Run all precommit steps even when some fail 2023-03-29 16:00:27 -07:00
Harry
e90639bcab
Make linter print useful output when failing on precommit
* Make linter print useful output when failing on precommit

* Update Scripts/precommit.py

Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>

Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
2022-10-31 14:05:27 -07:00
Evan Hahn
f07735f706 Precommit script should fail if lint fails
This change should have no user impact.

I thought I did this in 1b00741b6d7dbfbe48e5b1c46f856902d0e6d02a...this
*actually* does it.
2022-10-28 15:51:02 -07:00
Evan Hahn
e757a34e9b Auto-fix licese header violations in precommit script
Also fixes a violation.
2022-10-17 21:08:59 -07:00
Evan Hahn
370ff654e7
Change license to AGPL
Change license to AGPL

This commit:

- Updates the `LICENSE` file

- Start every file with something like:

      // Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
      // SPDX-License-Identifier: AGPL-3.0-only

---

First, I removed existing license headers with this Ruby 3.1.2 script:

    require 'set'

    EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']

    same = 0
    different = 0

    all_files = `git ls-files`.lines.map { |line| line.strip }
    all_files.each do |relative_path|
      if relative_path == 'Pods'
        next
      end

      unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
        next
      end

      path = File.expand_path(relative_path)

      contents = File.read(path)
      new_contents = contents.sub(/\/\/\n\/\/  Copyright .*\n\/\/\n\n/, '')

      if contents == new_contents
        same += 1
      else
        different += 1
      end

      File.write(path, new_contents)
    end

    puts "updated #{different} file(s), left #{same} untouched"

I'm sure this script could be improved, but it worked well enough.

Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.

Then I fixed some stragglers and updated the precommit script.

See [a similar change in the Desktop app][0].

[0]: 8bfaf598af
2022-10-13 08:25:37 -05:00
Evan Hahn
1b00741b6d
Fix remaining SwiftLint failures, lint more strictly
This fixes our remaining SwiftLint violations, which were small.

It also updates the precommit script to fail if any violations are
found, even warnings. This will cause CI to fail if you include a file
that isn't SwiftLint-compatible.
2022-10-07 12:00:26 -05:00
Max Radermacher
39135003a4 Fetch translations from Smartling
Smartling exposes a simple REST API that’s fairly easy to adopt.

Some differences from the old approach:

- We get UTF-8 back instead of UTF-16, so there’s no need to use iconv.

- We don’t support “nb_NO”, so we don’t need to remove it each time we
  fetch translations.

- We get back English fallbacks for .stringsdict files, so there’s no
  need to merge them manually ourselves.

- We no longer support country-specific locales *and* the root language,
  so we don’t need to merge, for example, “es” into “es-MX”.

- We handle language mapping & duplication inside the Swift script,
  which will hopefully be more reliable than cp’ing directories.
2022-09-29 16:13:06 -07:00
Sasha Weiss
901b24bf0a
Sort the Xcode project's visible files 2022-08-19 15:38:25 -07:00
Evan Hahn
f8afc58b42 Prefer clang-format for sorting #import/#include
This should have no direct user impact.

We currently have two ways of sorting `#import` and `#include`
statements:

1. With our precommit script
2. With `clang-format` (via `git-clang-format`)

It *looks* like we aren't using `clang-format` (because of the
`SortIncludes: false` option in `.clang-format`) but we are,
which you can see by running `clang-format --dump-config`. As a separate
issue, it seems like we're not picking up the `clang-format`
configuration file (`clang-format --style=file:.clang-format
--dump-config` gives different results).

I've run into situations where the two of them "fight", so I think the
best thing to do is pick one. After some discussion, we decided to pick
`clang-format`.
2022-08-05 08:01:03 -05:00
Max Radermacher
9105b0655d Fix precommit.py output for keyword matches
We were passing `bytes` to `print(...)`, which outputs an escaped
representation. We should pass a string, as we do elsewhere.
2022-07-27 05:31:51 -05:00
Evan Hahn
7149dd6c99 Autoformat precommit script
This auto-formats the precommit script with [Black][0]. I made no manual
changes as part of this commit.

[0]: https://github.com/psf/black
2022-05-10 12:40:13 -05:00
Evan Hahn
d7c33eb211 Speed up pre-commit script
On my machine, the `./precommit.py --all` took 344.15 seconds (more than
5 minutes). This change speeds it up so that it takes less than 10
seconds.

It primarily achieves this by running `swiftlint` twice instead of twice
per file. There are some other smaller changes, too:

- Use a `set` for common operations
- Avoid a needless call to `text.split`
- Use built-in `pathlib.Path().parts` instead of a home-rolled solution

Tested this by running `./precommit.py` with all flags.
2022-03-23 09:43:21 -05:00
Evan Hahn
a7d5f778e2 Fix pre-commit block format script
Python 3 removed the [`cmp` function][0] which this script relied on.
Calling it was unnecessary, so I removed it (and cleaned up some of the
surrounding code).

Tested this with the `--all`, `--path`, and `--ref` flags.

[0]: https://docs.python.org/2.7/library/functions.html#cmp
2022-03-22 13:33:32 -05:00
Evan Hahn
c254811765 Remove unnecessary coding: utf-8 heading from Python scripts
Python 3 uses UTF-8 for source files by default. This removes the
unnecessary `coding: utf-8` declaration comment from all files.
2022-03-21 14:43:45 -05:00
Evan Hahn
1101db6a29 Upgrade scripts to Python 3
Python 2 was [removed from macOS in 12.3][0]. This change:

- Automatically converts many files with [2to3][1]
- Manually updates all [shebangs][2] to use `python3` instead of
  versionless `python` or `python2.7`
- Manually applies a few fixes, many of which were noted by 2to3
- Manually undoes a few fixes that were automatically done by 2to3

[0]: https://www.macrumors.com/2022/01/28/apple-removing-python-2-in-macos-12-3/
[1]: https://docs.python.org/3/library/2to3.html
[2]: https://en.wikipedia.org/wiki/Shebang_(Unix)
2022-03-21 12:58:33 -05:00
Michelle Linington
220a49134e Fix lint script 2022-01-31 11:00:13 -08:00
Matthew Chen
726fa6577f Fix bug around handling forward declarations of obj-c protocols in precommit script. 2021-11-23 14:16:35 -03:00
Michelle Linington
7a3f063276 Fix clang format 2021-11-03 13:46:03 -07:00
Matthew Chen
9211ac8fa3 Move MobileCoin SDK to SignalUI. 2021-11-02 14:26:03 -03:00
Matthew Chen
a0efdc2e95 Respond to CR. 2021-10-21 09:21:33 -03:00
Matthew Chen
eca3fdf26f Respond to CR. 2021-10-21 09:21:33 -03:00
Michelle Linington
6028212361 Re-add swiftlint --fix invocation 2021-10-12 11:46:44 -07:00
Michelle Linington
fa190b88cd Skip files where sourcekitd crashes 2021-10-12 11:46:44 -07:00
Michelle Linington
d2de17afb9 Fix lint script 2021-10-12 11:46:44 -07:00
Nora Trapp
da59806acf Update precommit.py for swiftlint 0.43.1 2021-03-17 13:15:51 -07:00
Nora Trapp
aa1f0ab39c Fix precommit script for when PRs remove files 2020-04-03 11:17:01 -07:00
Ehren Kret
82f3f3ed01 Change shebang line for pre and post commit scripts
These scripts are written for Python 2.7 and fail if python executable
points to Python 3.
2020-04-01 18:09:57 -07:00
Nora Trapp
f05f2ff85f Add lint action 2020-03-14 15:40:02 -07:00
Nora Trapp
778885db9f Fix precommit, git-clang-format doesn't like spaces between extension type 2019-11-15 14:17:46 -08:00
Michael Kirk
583077d94b skip formatting proto files 2019-11-06 21:24:53 -07:00
Nora Trapp
03f3f4aa9a Don't disable universal support in precommitt 2019-10-23 13:46:31 -07:00
Nora Trapp
06f66b7cb5 Disable universal device support in precommit check. 2019-10-03 11:54:00 -07:00
Disconnect3d
0fc0377d0c Fix check_diff_for_keywords in scripts
Fixes the `objc_keywords` list in `check_diff_for_keywords`.

This list stores strings and Python automagically concatenates strings if there is no comma between them.

As a result the first two items of the list: `OWSAbstractMethod\(` and `OWSAssert\(` were wrongly conacatenated into `"OWSAbstractMethod\(OWSAssert\("`.

This has been found with LGTM 0ddaedbfad/files/Scripts/precommit.py (x84c147336239d4b6):1
2019-09-15 09:40:02 -07:00
Michael Kirk
5236fba691 keyword checks 2018-09-17 09:50:22 -06:00
Michael Kirk
551102210e include C assert variants in keywords check 2018-09-17 09:36:44 -06:00
Michael Kirk
d534651ac4 check keywords in diff 2018-09-07 11:02:56 -06:00
Matthew Chen
49b0ea993d Dedupe forward class declarations. 2018-07-12 15:35:42 -04:00
Michael Kirk
17ed0f6100 dedupe git hooks
// FREEBIE
2018-03-02 17:57:58 -05:00