Skip to content

feat: Linter rule for enforcing the use of game:GetService() #649

@NatFletch

Description

@NatFletch

As a Roblox Developer, I'd like to request a new linter rule that warns when developers try to directly access services (eg: game.Players) instead of using the preferred way which is using game:GetService("Players").

Disallow direct property access:

local Players = game.Players
local ReplicatedStorage = game.ReplicatedStorage

Require GetService() to access services

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

Rationale:

  • game:GetService() matches Roblox's recommended coding practices
  • Allows developers to have consistent looking code
  • It is safer to use game:GetService() as sometimes directly accessing services may not exist yet

Potential Implementation:

  • A linter rule named roblox_incorrect_service_get
  • Detect code that uses game.<ServiceName> when <ServiceName> is a real Roblox service

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions