Skip to content

Commit

Permalink
Add a lint rule to prevent importing outside of module boundaries.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: b6f35ff58a20bb01ea2110507ba82e9eda1de435
  • Loading branch information
cpojer committed Aug 6, 2024
1 parent ff2a87c commit 0703844
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 39 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
},
{
files: [
'.eslintrc.cjs',
'eslint-plugin/index.js',
'i18n/Common.cjs',
'infra/babelPlugins.tsx',
Expand All @@ -54,8 +55,14 @@ module.exports = {
'@typescript-eslint/no-require-imports': 0,
},
},
{
files: ['**/__tests__/**/*.tsx'],
rules: {
'workspaces/no-relative-imports': 0,
},
},
],
plugins: ['@deities'],
plugins: ['@deities', 'workspaces'],
rules: {
'@typescript-eslint/array-type': [2, { default: 'generic' }],
'@typescript-eslint/no-restricted-imports': [
Expand Down Expand Up @@ -116,5 +123,7 @@ module.exports = {
],
'no-extra-parens': 0,
'no-restricted-globals': [2, 'alert', 'confirm'],
'workspaces/no-absolute-imports': 2,
'workspaces/no-relative-imports': 2,
},
};
30 changes: 15 additions & 15 deletions athena/lib/resizeMap.tsx → apollo/lib/resizeMap.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { generateRandomMap } from '@deities/athena/generator/MapGenerator.tsx';
import { Decorator } from '@deities/athena/info/Decorator.tsx';
import { getTileInfo, TileTypes } from '@deities/athena/info/Tile.tsx';
import { verifyMap } from '@deities/athena/lib/verifyTiles.tsx';
import withModifiers from '@deities/athena/lib/withModifiers.tsx';
import { DecoratorsPerSide } from '@deities/athena/map/Configuration.tsx';
import Entity from '@deities/athena/map/Entity.tsx';
import { PlainEntitiesList } from '@deities/athena/map/PlainMap.tsx';
import { decodeDecorators } from '@deities/athena/map/Serialization.tsx';
import SpriteVector from '@deities/athena/map/SpriteVector.tsx';
import vec from '@deities/athena/map/vec.tsx';
import Vector from '@deities/athena/map/Vector.tsx';
import MapData, { SizeVector } from '@deities/athena/MapData.tsx';
import { objectiveHasVectors } from '@deities/athena/Objectives.tsx';
import ImmutableMap from '@nkzw/immutable-map';
import { Effects } from '../../apollo/Effects.tsx';
import { generateRandomMap } from '../generator/MapGenerator.tsx';
import { Decorator } from '../info/Decorator.tsx';
import { getTileInfo, TileTypes } from '../info/Tile.tsx';
import { DecoratorsPerSide } from '../map/Configuration.tsx';
import Entity from '../map/Entity.tsx';
import { PlainEntitiesList } from '../map/PlainMap.tsx';
import { decodeDecorators } from '../map/Serialization.tsx';
import SpriteVector from '../map/SpriteVector.tsx';
import vec from '../map/vec.tsx';
import Vector from '../map/Vector.tsx';
import MapData, { SizeVector } from '../MapData.tsx';
import { objectiveHasVectors } from '../Objectives.tsx';
import { verifyMap } from './verifyTiles.tsx';
import withModifiers from './withModifiers.tsx';
import { Effects } from '../Effects.tsx';

export type ResizeOrigin = 'top' | 'right' | 'bottom' | 'left';

Expand Down
4 changes: 2 additions & 2 deletions athena/lib/determineUnitsToCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import ImmutableMap from '@nkzw/immutable-map';
import { PotentialUnitAbilities } from '../../dionysus/lib/getPossibleUnitAbilities.tsx';
import needsSupply from '../../dionysus/lib/needsSupply.tsx';
import { BuildableTiles, MinFunds } from '../info/Building.tsx';
import { Ability, UnitInfo } from '../info/Unit.tsx';
import Building from '../map/Building.tsx';
Expand All @@ -12,6 +10,8 @@ import MapData from '../MapData.tsx';
import calculateFunds, {
calculateTotalPossibleFunds,
} from './calculateFunds.tsx';
import { PotentialUnitAbilities } from './getPossibleUnitAbilities.tsx';
import needsSupply from './needsSupply.tsx';

export default function determineUnitsToCreate(
map: MapData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Ability, UnitInfo } from '@deities/athena/info/Unit.tsx';
import Building from '@deities/athena/map/Building.tsx';
import Player from '@deities/athena/map/Player.tsx';
import { Ability, UnitInfo } from '../info/Unit.tsx';
import Building from '../map/Building.tsx';
import Player from '../map/Player.tsx';

export type PotentialUnitAbilities = Readonly<{
canCreateBuildUnits: boolean;
Expand Down
4 changes: 2 additions & 2 deletions dionysus/lib/needsSupply.tsx → athena/lib/needsSupply.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hasLowAmmoSupply from '@deities/athena/lib/hasLowAmmoSupply.tsx';
import Unit from '@deities/athena/map/Unit.tsx';
import Unit from '../map/Unit.tsx';
import hasLowAmmoSupply from './hasLowAmmoSupply.tsx';

const needsFuel = (unit: Unit) =>
unit.fuel <= unit.info.configuration.fuel * 0.3;
Expand Down
2 changes: 1 addition & 1 deletion athena/lib/validateMap.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import isPositiveInteger from '@deities/hephaestus/isPositiveInteger.tsx';
import ImmutableMap from '@nkzw/immutable-map';
import AIRegistry from '../../dionysus/AIRegistry.tsx';
import {
Behavior,
getBuildingInfo,
Expand Down Expand Up @@ -215,6 +214,7 @@ export const validateUnit = (

export default function validateMap(
map: MapData,
AIRegistry: { has: (ai: number) => boolean },
newTeams?: TeamsList,
hasContentRestrictions?: boolean,
skills?: ReadonlySet<Skill>,
Expand Down
2 changes: 1 addition & 1 deletion dionysus/BaseAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import gameHasEnded from '@deities/apollo/lib/gameHasEnded.tsx';
import { GameState } from '@deities/apollo/Types.tsx';
import MapData from '@deities/athena/MapData.tsx';
import { VisionT } from '@deities/athena/Vision.tsx';
import getActivatePowerMessage from '../hermes/messages/getActivatePowerMessage.tsx';
import getActivatePowerMessage from '@deities/hermes/messages/getActivatePowerMessage.tsx';

class AIInterruptException {
public readonly name = 'AIInterruptException';
Expand Down
8 changes: 4 additions & 4 deletions dionysus/DionysusAlpha.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ import canDeploy from '@deities/athena/lib/canDeploy.tsx';
import canPlaceLightning from '@deities/athena/lib/canPlaceLightning.tsx';
import determineUnitsToCreate from '@deities/athena/lib/determineUnitsToCreate.tsx';
import getDeployableVectors from '@deities/athena/lib/getDeployableVectors.tsx';
import getPossibleUnitAbilities, {
getPossibleUnitAbilitiesForBuildings,
} from '@deities/athena/lib/getPossibleUnitAbilities.tsx';
import getRescuableVectors from '@deities/athena/lib/getRescuableVectors.tsx';
import getUnitsToRefill from '@deities/athena/lib/getUnitsToRefill.tsx';
import hasUnitsOrProductionBuildings from '@deities/athena/lib/hasUnitsOrProductionBuildings.tsx';
import needsSupply from '@deities/athena/lib/needsSupply.tsx';
import { AIBehavior } from '@deities/athena/map/AIBehavior.tsx';
import Building from '@deities/athena/map/Building.tsx';
import { Charge } from '@deities/athena/map/Configuration.tsx';
Expand Down Expand Up @@ -64,11 +68,7 @@ import getBuildingWeight from './lib/getBuildingWeight.tsx';
import getInterestingVectors from './lib/getInterestingVectors.tsx';
import getInterestingVectorsByAbilities from './lib/getInterestingVectorsByAbilities.tsx';
import getPossibleAttacks from './lib/getPossibleAttacks.tsx';
import getPossibleUnitAbilities, {
getPossibleUnitAbilitiesForBuildings,
} from './lib/getPossibleUnitAbilities.tsx';
import getUnitInfosWithMaxVision from './lib/getUnitInfosWithMaxVision.tsx';
import needsSupply from './lib/needsSupply.tsx';
import shouldActivatePower from './lib/shouldActivatePower.tsx';
import shouldAttack from './lib/shouldAttack.tsx';
import shouldCaptureBuilding from './lib/shouldCaptureBuilding.tsx';
Expand Down
2 changes: 1 addition & 1 deletion dionysus/lib/getInterestingVectors.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BuildableTiles } from '@deities/athena/info/Building.tsx';
import { Beach, isSeaTile } from '@deities/athena/info/Tile.tsx';
import { Ability } from '@deities/athena/info/Unit.tsx';
import needsSupply from '@deities/athena/lib/needsSupply.tsx';
import { AIBehavior } from '@deities/athena/map/AIBehavior.tsx';
import { EntityType, getEntityGroup } from '@deities/athena/map/Entity.tsx';
import Unit from '@deities/athena/map/Unit.tsx';
import Vector from '@deities/athena/map/Vector.tsx';
import MapData from '@deities/athena/MapData.tsx';
import getObjectiveVectors from './getObjectiveVectors.tsx';
import needsSupply from './needsSupply.tsx';
import shouldCaptureBuilding from './shouldCaptureBuilding.tsx';

export default function getInterestingVectors(
Expand Down
4 changes: 2 additions & 2 deletions dionysus/lib/getInterestingVectorsByAbilities.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BuildableTiles } from '@deities/athena/info/Building.tsx';
import { PotentialUnitAbilities } from '@deities/athena/lib/getPossibleUnitAbilities.tsx';
import needsSupply from '@deities/athena/lib/needsSupply.tsx';
import Player, { PlayerID } from '@deities/athena/map/Player.tsx';
import Vector from '@deities/athena/map/Vector.tsx';
import MapData from '@deities/athena/MapData.tsx';
import { Criteria, objectiveHasVectors } from '@deities/athena/Objectives.tsx';
import { PotentialUnitAbilities } from './getPossibleUnitAbilities.tsx';
import needsSupply from './needsSupply.tsx';
import shouldCaptureBuilding from './shouldCaptureBuilding.tsx';

export default function getInterestingVectorsByAbilities(
Expand Down
10 changes: 8 additions & 2 deletions hera/editor/MapEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
encodeEffects,
Scenario,
} from '@deities/apollo/Effects.tsx';
import resizeMap, { ResizeOrigin } from '@deities/apollo/lib/resizeMap.tsx';
import { Route } from '@deities/apollo/Routes.tsx';
import getCampaignRoute from '@deities/apollo/routes/getCampaignRoute.tsx';
import {
Expand All @@ -18,7 +19,6 @@ import { Bush } from '@deities/athena/info/Decorator.tsx';
import { getTileInfo, Plain } from '@deities/athena/info/Tile.tsx';
import createBotWithName from '@deities/athena/lib/createBotWithName.tsx';
import dropInactivePlayers from '@deities/athena/lib/dropInactivePlayers.tsx';
import resizeMap, { ResizeOrigin } from '@deities/athena/lib/resizeMap.tsx';
import startGame from '@deities/athena/lib/startGame.tsx';
import UnlockableBiomes from '@deities/athena/lib/UnlockableBiomes.tsx';
import updateActivePlayers from '@deities/athena/lib/updateActivePlayers.tsx';
Expand All @@ -30,6 +30,7 @@ import { DoubleSize, TileSize } from '@deities/athena/map/Configuration.tsx';
import { HumanPlayer, PlayerID } from '@deities/athena/map/Player.tsx';
import { toTeamArray } from '@deities/athena/map/Team.tsx';
import MapData, { SizeVector } from '@deities/athena/MapData.tsx';
import AIRegistry from '@deities/dionysus/AIRegistry.tsx';
import getFirstOrThrow from '@deities/hephaestus/getFirstOrThrow.tsx';
import random from '@deities/hephaestus/random.tsx';
import { ClientGame } from '@deities/hermes/game/toClientGame.tsx';
Expand Down Expand Up @@ -420,7 +421,11 @@ export default function MapEditor({
(map: MapData, retainMap = false, actAsEveryPlayer = false) => {
const playTest = !isPlayTesting;
const [currentMap, error] = playTest
? validateMap(map, toTeamArray(dropInactivePlayers(map).teams))
? validateMap(
map,
AIRegistry,
toTeamArray(dropInactivePlayers(map).teams),
)
: [map];
if (!currentMap) {
setSaveState({ message: getMapValidationErrorText(error) });
Expand Down Expand Up @@ -487,6 +492,7 @@ export default function MapEditor({

const [map, error] = validateMap(
currentMap,
AIRegistry,
toTeamArray(dropInactivePlayers(currentMap).teams),
);
if (!map || error) {
Expand Down
2 changes: 1 addition & 1 deletion hera/editor/ResizeHandle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResizeOrigin } from '@deities/athena/lib/resizeMap.tsx';
import { ResizeOrigin } from '@deities/apollo/lib/resizeMap.tsx';
import {
MaxSize,
MinSize,
Expand Down
2 changes: 2 additions & 0 deletions hera/editor/panels/EvaluationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import startGame from '@deities/athena/lib/startGame.tsx';
import updateActivePlayers from '@deities/athena/lib/updateActivePlayers.tsx';
import validateMap from '@deities/athena/lib/validateMap.tsx';
import { toTeamArray } from '@deities/athena/map/Team.tsx';
import AIRegistry from '@deities/dionysus/AIRegistry.tsx';
import groupBy from '@deities/hephaestus/groupBy.tsx';
import sortBy from '@deities/hephaestus/sortBy.tsx';
import { ClientGame } from '@deities/hermes/game/toClientGame.tsx';
Expand Down Expand Up @@ -48,6 +49,7 @@ export default function EvaluationPanel({
const currentMap = useMemo(() => {
const [currentMap] = validateMap(
state.map,
AIRegistry,
toTeamArray(dropInactivePlayers(state.map).teams),
);

Expand Down
2 changes: 1 addition & 1 deletion hera/editor/panels/MapEditorControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Effect, Scenario } from '@deities/apollo/Effects.tsx';
import { ResizeOrigin } from '@deities/athena/lib/resizeMap.tsx';
import { ResizeOrigin } from '@deities/apollo/lib/resizeMap.tsx';
import MapData, { SizeVector } from '@deities/athena/MapData.tsx';
import isPresent from '@deities/hephaestus/isPresent.tsx';
import UnknownTypeError from '@deities/hephaestus/UnknownTypeError.tsx';
Expand Down
2 changes: 1 addition & 1 deletion hera/editor/panels/MapEditorSettingsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ResizeOrigin } from '@deities/apollo/lib/resizeMap.tsx';
import hasBonusObjective from '@deities/athena/lib/hasBonusObjective.tsx';
import { ResizeOrigin } from '@deities/athena/lib/resizeMap.tsx';
import {
DoubleSize,
MaxSize,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"chalk": "^5.3.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-plugin-workspaces": "^0.10.1",
"nodemon": "^3.1.4",
"npm-run-all2": "^6.2.2",
"prettier": "4.0.0-alpha.8",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tests/__tests__/MapGenerator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import validateMap from '@deities/athena/lib/validateMap.tsx';
import withModifiers from '@deities/athena/lib/withModifiers.tsx';
import { HumanPlayer } from '@deities/athena/map/Player.tsx';
import { SizeVector } from '@deities/athena/MapData.tsx';
import AIRegistry from '@deities/dionysus/AIRegistry.tsx';
import random from '@deities/hephaestus/random.tsx';
import { expect, test } from 'vitest';
import { printGameState } from '../printGameState.tsx';
Expand All @@ -21,14 +22,14 @@ test('creates valid maps', async () => {
),
),
);
const validatedMap = validateMap(map);
const validatedMap = validateMap(map, AIRegistry);
if (!validatedMap) {
printGameState(
`Invalid Map`,
await captureOne(map, HumanPlayer.from(map.getPlayer(1), '1').userId),
);
console.log(JSON.stringify(map.toJSON(), null, 2));
}
expect(validateMap(map)).not.toBeFalsy();
expect(validateMap(map, AIRegistry)).not.toBeFalsy();
}
});

0 comments on commit 0703844

Please sign in to comment.