Add ${file} token; only set token if expansion is available
@@ -495,29 +495,35 @@ class Linter(metaclass=LinterMeta):
# Expressions are evaluated in list order.
expressions = []
window = self.view.window()
- if window:
filename = self.view.file_name()
- project = self._guess_project_path(window, filename)
- if project:
+ if filename:
expressions.append({
- 'token': '${project}',
- 'value': project.replace('\\', '/')
+ 'token': '${file}',
+ 'value': filename.replace('\\', '/')
})
- directory = (
- os.path.dirname(filename).replace('\\', '/') if
- filename else "FILE NOT ON DISK")
-
+ directory = os.path.dirname(filename) if filename else None
+ if directory:
expressions.append({
'token': '${directory}',
- 'value': directory
+ 'value': directory.replace('\\', '/')
+ })
+
+ if window:
+ project = self._guess_project_path(window, filename)
+ if project:
+ expressions.append({
+ 'token': '${project}',
+ 'value': project.replace('\\', '/')
})
window_vars = window.extract_variables()
+ root = window_vars.get('folder', None) or directory
+ if root:
expressions.append({
'token': '${root}',
- 'value': window_vars.get('folder', None) or directory
+ 'value': root.replace('\\', '/')
})
project_base_name = window_vars.get('project_base_name', None)
@@ -527,9 +533,11 @@ class Linter(metaclass=LinterMeta):
'value': project_base_name
})
+ home = os.path.expanduser('~').rstrip(os.sep).rstrip(os.altsep)
+ if home:
expressions.append({
'token': '${home}',
- 'value': os.path.expanduser('~').rstrip(os.sep).rstrip(os.altsep).replace('\\', '/') or 'HOME NOT SET'
+ 'value': home.replace('\\', '/')
})
expressions.append({
