Deprecation cop, finally annoying me enough to ask for a fix


I have this in my Init file, my company uses odd php extensions for various files, so below is 1 of a couple ways I get the editor to recognize what language is being used. Is there a non-deprecated was to do this?

path = require 'path'
atom.workspace.observeTextEditors (editor) ->
    if path.extname(editor.getPath()) == '.phpX'


What is the deprecation warning?

your local file (1 deprecation)
Argument to path.extname must be a string
Object.extname - C:\Users\sworkm2\AppData\Local\atom\app-1.19.0\resources\app\src\electron-
<unknown> - C:\Users\sworkm2\.atom\
<unknown> - <embedded>:26160:22
Function.module.exports.Emitter.simpleDispatch - <embedded>:63277:20
Emitter.emit - <embedded>:63393:34
<unknown> - <embedded>:26033:34


editor.getPath() can return undefined. Make sure it isn’t undefined before passing it to path.extname().


the code works. I’m just trying to remove the deprecation warning. How would I go about making sure .getPath() isn’t undefined, throwing it in a variable first? not familiar with coffee script.



Having code do the job is not required. There is a configuration setting you can use to include .phpX to the scope of text.html.php.

Recently was posted:

This will work for you, just follow the link in text
… or do you want the coding method?..


Yes, precisely. I imagine something like the following:

# ...
filePath = editor.getPath()
if filePath? and path.extname(filePath) is '.phpX'
  # ...

Also, if you’re more familiar with JS than Coffee, Atom recognizes init.js as well.