I've been trying to add my first snippet in the Atom text editor and I keep getting the error that there's an unexpected newline.


#1

‘.source.js’:
‘Console log’:
‘prefix’: ‘log’
‘body’: ‘console.log($1)’

‘Constructor’:
‘prefix’: ‘rcon’
‘body’:"""
constructor(props){
super(props);

         this.state = {$1};
      }
    """

'Component':
   'prefix': 'rcom'
   'body': """
       class $1 extends Component {
         render(){
           return(
           	  <div>
           	  	 $2
           	  </div>
           );
         }
      }
    """

#2

When posting code, please remember to mark it as code so that we can read it. There are plenty of resources online about how to use GitHub-Flavored Markdown syntax, but on this forum you can also highlight your code and press the </> button right above the editor.


#3

k but how to fix that problem


#4

We don’t know what’s wrong if we can’t see it exactly as it is in the file. You need to either edit your post, or comment below with the correctly marked up version (use the preview tab to verify it worked)


#5

-------- BUG ALERT --------


Hello.

I have tried the given snippets within Atom V1.28.0. The first problem is that the above snippets is written with smart quotes where simple single quote ' is expected.

First attempting in plain text file; meaning changing .source.js to .text.plain. The snippets.cson files looks as follows, and tested correctly for a plain text file.

### snippets.cson ###
'.text.plain':
  'Console log':
    'prefix': 'log'
    'body': 'console.log($1)'

  'Constructor':
    'prefix': 'rcon'
    'body':"""
    constructor(props){
    super(props);

             this.state = {$1};
          }
    """
  
  'Component':
     'prefix': 'rcom'
     'body': """
         class $1 extends Component {
           render(){
             return(
             	  <div>
             	  	 $2
             	  </div>
             );
           }
        }
      """

Changing .text.plain to the required .source.js has a strange behaviour. ALL previously system loaded snippets as well as the new user snippets are removed, accept legal. Even making the prefixes to a very unique xlog, xrcon and xrcom did not help the situation.

The behaviour does not repeat in atom --safe, nor in my version of Atom V1.29-Beta 0.

Could someone please confirm this behaviour on their systems too. It is very possible that what I am seeing is a totally new issue unique to my install.

BR


#6

<continued from previous>

The problem is with Tree Sitter.

The issue I have reported earlier is not a problem if Use Tree Sitter Parsers is deactivated. User defined snippets for JavaScript works again if this option is off (opposite of picture).

My BETA copy had this option already off, that is why it worked at first.



EDIT 1
To reproduce issue on Windows10,
with Atom V1.28.0 (fixed) or Atom V1.29-Beta0 (portable):
(ATOM-IDE is not active)

  1. Open Atom normally.

  2. Close all centre panes (must?).

  3. Toggle “Tree Sitter Parser” in Settings.

  4. Close Settings (optional).

  5. Close Atom or restart by ctrl-shift-F5.

  6. Open Atom normally.

  7. Create new text file ctrl-n.

  8. Select grammar ctrl-shift-l:
    Core versions of JavaScript or Python.

  9. Toggle command pallet ctrl-shift-p
    and type in Snippets: Available

  10. Note result.

Value (3) Result in (10)
ON Only legal is shown as possible snippets
OFF All snippets including snippets.cson is shown



#7

Let me repeat my answer from your Stack Overflow post:

CSON files need to indented correctly, and your file isn’t:

'.source.js':
  'Console log':
    'prefix': 'log'
    'body': 'console.log($1)$0'
  'Constructor':
    'prefix': 'rcon'
    'body': """
        constructor(props){
            super(props);
            this.state = {$1};
        }$0
    """
  'Component':
    'prefix': 'rcom'
    'body': """
        class $1 extends Component {
            render(){
                return(
                    <div>
                        $2
                    </div>
                );
            }
        }$0
    """

If you install a linter such as linter-coffeelint, Atom will highlight these errors directly in the source.