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


#1

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?
Best,

path = require 'path'
atom.workspace.observeTextEditors (editor) ->
    if path.extname(editor.getPath()) == '.phpX'
        editor.setGrammar(atom.grammars.grammarForScopeName('text.html.php'))

#2

What is the deprecation warning?


#4
your local init.coffee 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-
shims.js:20:10
<unknown> - C:\Users\sworkm2\.atom\init.coffee:7:14
<unknown> - <embedded>:26160:22
Function.module.exports.Emitter.simpleDispatch - <embedded>:63277:20
Emitter.emit - <embedded>:63393:34
<unknown> - <embedded>:26033:34

#5

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


#6

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.


#7

Hello.

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?..
Cheers.


#8

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.