Skip to content

Commit

Permalink
feat(ci): Add the EditorConfig style checker to CI (endless-sky#6815)
Browse files Browse the repository at this point in the history
* Add editorconfig style checker CI.

* Fix every editorconfig style violation.

* Fix editorconfig file and (almost) all the violations found.

* Fix comments.

* Fix remaining style violations.

* Correct my previous mistake.

* Address review comments.

* Address review comments.

* Fix remaining style violations.
  • Loading branch information
quyykk authored May 21, 2022
1 parent a128490 commit b17025c
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 122 deletions.
3 changes: 3 additions & 0 deletions .ecrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Exclude": ["\\.mp3$", "test_datafile.cpp", "\\Shader.cpp$", "Font.cpp", "Mask.cpp"]
}
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ trim_trailing_whitespace = false
indent_style = tab

# Code files
[*.{cpp,h,rc,hpp}, SConstruct, SConscript]
[{*.{cpp,h,rc,hpp}, SConstruct, SConscript}]
indent_style = tab
# Except any third-party libraries
[catch.hpp]
indent_style = unset

# Markdown
[*.md]
Expand Down
70 changes: 35 additions & 35 deletions .github/path-filters.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
data:
- 'changelog*'
- 'copyright*'
- credits.txt
- icon.png
- keys.txt
- license.txt
- 'data/**/*'
- 'images/**/*'
- 'sounds/**/*'
- 'changelog*'
- 'copyright*'
- credits.txt
- icon.png
- keys.txt
- license.txt
- 'data/**/*'
- 'images/**/*'
- 'sounds/**/*'

game_code: &build
- 'source/**'
- 'source/**'

macos:
- 'XCode/**'
- '**/*.xcodeproj'
- 'icons/endless-sky.iconset/**'
- 'utils/fetch_sdl2_framework.sh'
- 'utils/set_dylibs_rpath.sh'
- *build
- 'XCode/**'
- '**/*.xcodeproj'
- 'icons/endless-sky.iconset/**'
- 'utils/fetch_sdl2_framework.sh'
- 'utils/set_dylibs_rpath.sh'
- *build

windows:
- '**/*.cbp'
- EndlessSky.workspace
- SConstruct
- .winmake
- *build
- '**/*.cbp'
- EndlessSky.workspace
- SConstruct
- .winmake
- *build

linux:
- SConstruct
- *build
- SConstruct
- *build

unit_tests:
- 'tests/unit/**/*.h'
- 'tests/unit/**/*.hpp'
- 'tests/unit/**/*.cpp'
- 'tests/unit/**/*.h'
- 'tests/unit/**/*.hpp'
- 'tests/unit/**/*.cpp'

integration_tests:
- 'utils/test_parse.*'
- 'tests/integration/run_tests*'
- 'data/tests/**'
- 'tests/integration/universes/**'
- 'utils/test_parse.*'
- 'tests/integration/run_tests*'
- 'data/tests/**'
- 'tests/integration/universes/**'

codespell:
- .codespell.exclude
- .codespell.exclude

xcode_files:
- 'EndlessSky.xcodeproj/**'
- 'utils/check_xcode.sh'
- 'EndlessSky.xcodeproj/**'
- 'utils/check_xcode.sh'

codeblocks_files:
- '*.cbp'
- 'utils/check_codeblocks.sh'
- '*.cbp'
- 'utils/check_codeblocks.sh'
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,12 @@ jobs:
builtin: clear,en-GB_to_en-US
path: data/
exclude_file: .codespell.exclude



style-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: editorconfig-checker/action-editorconfig-checker@main
- run: editorconfig-checker
2 changes: 1 addition & 1 deletion data/remnant/remnant 1 introduction.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3741,4 +3741,4 @@ mission "Remnant: Expanded Horizons Storms 1"
` She looks at you quizzically for a moment, and then her display shifts to a mass of symbols. She skims briefly. "I have never even heard of such a unit. Apparently it is a very old one, though. Our records say that it had largely stopped being used by early in the 21st century. Well, I learned something new today." The display and its field of symbols vanishes as she slings her backpack over her shoulder.`
label stormend
` "Thanks for the ride, Captain. I have to get working on this data, but if you are interested in helping some more, I hope to have more research expeditions planned soon."`

2 changes: 1 addition & 1 deletion source/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,7 @@ void AI::MovePlayer(Ship &ship, const PlayerInfo &player, Command &activeCommand
{
PrepareForHyperspace(ship, command);
command |= Command::JUMP;

// Don't jump yet if the player is holding jump key or fleet jump is active and
// escorts are not ready to jump yet.
if(activeCommands.Has(Command::WAIT) || (autoPilot.Has(Command::FLEET_JUMP) && !EscortsReadyToJump(ship)))
Expand Down
2 changes: 1 addition & 1 deletion source/Fleet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void Fleet::RemoveInvalidVariants()
auto removeIt = remove_if(firstInvalid, variants.end(), IsInvalidVariant);
int count = distance(removeIt, variants.end());
variants.erase(removeIt, variants.end());

Files::LogError("Warning: " + (fleetName.empty() ? "unnamed fleet" : "fleet \"" + fleetName + "\"")
+ ": Removing " + to_string(count) + " invalid " + (count > 1 ? "variants" : "variant")
+ " (" + to_string(total - variants.TotalWeight()) + " of " + to_string(total) + " weight)");
Expand Down
4 changes: 2 additions & 2 deletions source/GameEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void GameEvent::Save(DataWriter &out) const
{
if(isDisabled)
return;

out.Write("event");
out.BeginChild();
{
Expand Down Expand Up @@ -218,7 +218,7 @@ void GameEvent::Apply(PlayerInfo &player)
{
if(isDisabled)
return;

// Serialize the current reputation with other governments.
player.SetReputationConditions();

Expand Down
14 changes: 7 additions & 7 deletions source/InfoPanelState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void InfoPanelState::SelectMany(int start, int end)
{
for(int i = start; i < end; ++i)
allSelected.insert(i);

if(selectedIndex == -1)
selectedIndex = *allSelected.begin();
}
Expand Down Expand Up @@ -146,11 +146,11 @@ bool InfoPanelState::ReorderShips(const set<int> &fromIndices, int toIndex)
{
if(fromIndices.empty() || static_cast<unsigned>(toIndex) >= ships.size())
return false;

// When shifting ships up in the list, move to the desired index. If
// moving down, move after the selected index.
int direction = (*fromIndices.begin() < toIndex) ? 1 : 0;

// Remove the ships from last to first, so that each removal leaves all the
// remaining indices in the set still valid.
vector<shared_ptr<Ship>> removed;
Expand All @@ -159,11 +159,11 @@ bool InfoPanelState::ReorderShips(const set<int> &fromIndices, int toIndex)
// The "it" pointer doesn't point to the beginning of the list, so it is
// safe to decrement it here.
--it;

// Bail out if any invalid indices are encountered.
if(static_cast<unsigned>(*it) >= ships.size())
return false;

removed.insert(removed.begin(), ships[*it]);
ships.erase(ships.begin() + *it);
// If this index is before the insertion point, removing it causes the
Expand All @@ -174,13 +174,13 @@ bool InfoPanelState::ReorderShips(const set<int> &fromIndices, int toIndex)
// Make sure the insertion index is within the list.
toIndex = min<int>(toIndex + direction, ships.size());
ships.insert(ships.begin() + toIndex, removed.begin(), removed.end());

// Change the selected indices so they still refer to the block of ships
// that just got moved.
int lastIndex = toIndex + allSelected.size();
DeselectAll();
SelectMany(toIndex, lastIndex);

// The ships are no longer sorted.
SetCurrentSort(nullptr);
return true;
Expand Down
30 changes: 15 additions & 15 deletions source/InfoPanelState.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,56 @@ class Ship;


// This class is responsible for storing the state
// between PlayerInfoPanel and ShipInfoPanel so that
// between PlayerInfoPanel and ShipInfoPanel so that
// things like scroll position, selection and sort are
// saved when the user is switching between the panels.
class InfoPanelState {
public:
using ShipComparator = bool (const std::shared_ptr <Ship>&, const std::shared_ptr <Ship>&);

InfoPanelState(PlayerInfo &player);

int SelectedIndex() const;
void SetSelectedIndex(int newSelectedIndex);

const std::set<int> &AllSelected() const;
void SetSelected(const std::set<int> &selected);
void Select(int index);
void SelectOnly(int index);
void SelectMany(int start, int end);
bool Deselect(int index);
void DeselectAll();

bool CanEdit() const;

int Scroll() const;
void SetScroll(int newScroll);

std::vector<std::shared_ptr<Ship>> &Ships();
const std::vector<std::shared_ptr<Ship>> &Ships() const;
bool ReorderShips(const std::set<int> &fromIndices, int toIndex);

ShipComparator *CurrentSort() const;
void SetCurrentSort(ShipComparator *s);


private:
// Most recent selected ship index.
int selectedIndex = -1;

// Indices of selected ships.
std::set<int> allSelected;

// A copy of PlayerInfo.ships for viewing and manipulating.
std::vector<std::shared_ptr<Ship>> ships;

// When the player is landed, they are able to
// change their flagship and reorder their fleet.
const bool canEdit = false;

// Index of the ship at the top of the fleet listing.
int scroll = 0;

// Keep track of whether the ships are sorted.
ShipComparator *currentSort = nullptr;
};
Expand Down
Loading

0 comments on commit b17025c

Please sign in to comment.