github.com/googleapis/api-linter@v1.65.2/rules/aip0140/reserved_words.go (about)

     1  // Copyright 2019 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // 		https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package aip0140
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"bitbucket.org/creachadair/stringset"
    21  	"github.com/googleapis/api-linter/lint"
    22  	"github.com/googleapis/api-linter/locations"
    23  	"github.com/jhump/protoreflect/desc"
    24  )
    25  
    26  var reservedWords = &lint.FieldRule{
    27  	Name: lint.NewRuleName(140, "reserved-words"),
    28  	LintField: func(f *desc.FieldDescriptor) []lint.Problem {
    29  		if name := f.GetName(); reservedWordsSet.Contains(name) {
    30  			return []lint.Problem{{
    31  				Message:    fmt.Sprintf("%q is a reserved word in a common language and should not be used.", name),
    32  				Descriptor: f,
    33  				Location:   locations.DescriptorName(f),
    34  			}}
    35  		}
    36  		return nil
    37  	},
    38  }
    39  
    40  var reservedWordsSet = stringset.New(
    41  	"abstract",     // Java, JavaScript
    42  	"and",          // Python
    43  	"arguments",    // JavaScript
    44  	"as",           // Python
    45  	"assert",       // Java, Python
    46  	"async",        // Python
    47  	"await",        // JavaScript, Python
    48  	"boolean",      // Java, JavaScript
    49  	"break",        // Java, JavaScript, Python
    50  	"byte",         // Java, JavaScript
    51  	"case",         // Java, JavaScript
    52  	"catch",        // Java, JavaScript
    53  	"char",         // Java, JavaScript
    54  	"class",        // Java, JavaScript, Python
    55  	"const",        // Java, JavaScript
    56  	"continue",     // Java, JavaScript, Python
    57  	"debugger",     // JavaScript
    58  	"def",          // Python
    59  	"default",      // Java, JavaScript
    60  	"del",          // Python
    61  	"delete",       // JavaScript
    62  	"do",           // Java, JavaScript
    63  	"double",       // Java, JavaScript
    64  	"elif",         // Python
    65  	"else",         // Java, JavaScript, Python
    66  	"enum",         // Java, JavaScript
    67  	"eval",         // JavaScript
    68  	"except",       // Python
    69  	"export",       // JavaScript
    70  	"extends",      // Java, JavaScript
    71  	"false",        // JavaScript
    72  	"final",        // Java, JavaScript
    73  	"finally",      // Java, JavaScript, Python
    74  	"float",        // Java, JavaScript
    75  	"for",          // Java, JavaScript, Python
    76  	"from",         // Python
    77  	"function",     // JavaScript
    78  	"global",       // Python
    79  	"goto",         // Java, JavaScript
    80  	"if",           // Java, JavaScript, Python
    81  	"implements",   // Java, JavaScript
    82  	"import",       // Java, JavaScript, Python
    83  	"in",           // JavaScript, JavaScript, Python
    84  	"instanceof",   // Java, JavaScript
    85  	"int",          // Java, JavaScript
    86  	"interface",    // Java, JavaScript
    87  	"is",           // Python
    88  	"lambda",       // Python
    89  	"let",          // JavaScript
    90  	"long",         // Java, JavaScript
    91  	"native",       // Java, JavaScript
    92  	"new",          // Java, JavaScript
    93  	"nonlocal",     // Python
    94  	"not",          // Python
    95  	"null",         // JavaScript
    96  	"or",           // Python
    97  	"package",      // Java, JavaScript
    98  	"pass",         // Python
    99  	"private",      // Java, JavaScript
   100  	"protected",    // Java, JavaScript
   101  	"public",       // Java, JavaScript
   102  	"raise",        // Python
   103  	"return",       // Java, JavaScript, Python
   104  	"short",        // Java, JavaScript
   105  	"static",       // Java, JavaScript
   106  	"strictfp",     // Java
   107  	"super",        // Java, JavaScript
   108  	"switch",       // Java, JavaScript
   109  	"synchronized", // Java, JavaScript
   110  	"this",         // Java, JavaScript
   111  	"throw",        // Java, JavaScript
   112  	"throws",       // Java, JavaScript
   113  	"transient",    // Java, JavaScript
   114  	"true",         // JavaScript
   115  	"try",          // Java, JavaScript, Python
   116  	"typeof",       // JavaScript
   117  	"var",          // JavaScript
   118  	"void",         // Java, JavaScript
   119  	"volatile",     // Java, JavaScript
   120  	"while",        // Java, JavaScript, Python
   121  	"with",         // JavaScript, Python
   122  	"yield",        // JavaScript, Python
   123  )