cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
962 stars 105 forks source link

Fix if(DEFINED ENV{var}) for CMAKE_* variables #281

Open Takishima opened 3 years ago

Takishima commented 3 years ago

MRE:

cmake_minimum_required(VERSION 3.0)
project(test LANGUAGES CXX)

if(DEFINED ENV{CMAKE_CXX_COMPILER_LAUNCHER})
  message(STATUS "Hello World!")
endif()

Expected:

No warnings

Actual:

/tmp/CMakeLists.txt
===================
/tmp/CMakeLists.txt:04,11: [W0106] String looks like a variable reference missing an open tag '{CMAKE_CXX_COMPILER_LAUNCHER'

Summary
=======
files scanned: 1
found lint:
     Warning: 1

This PR addresses this by patching the LintChecker::check_tokens() function to check for cases where the first group of the match happens to be ENV{.