Skip to content

Commit

Permalink
Merge pull request #127 from ditrit/improvement/required_attribute
Browse files Browse the repository at this point in the history
Improvement: required attribute
  • Loading branch information
Zorin95670 authored Aug 2, 2024
2 parents 827bded + 7453d14 commit c327256
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
4 changes: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Default attributes for metadata.
- Error management.
- I18n management.
- Unknown definition attribute.
- New attribute for Unknown component definition.

### Changed

- Update plugin-core to version 0.26.0.
- Update plugin-core to version 0.26.2.

## [0.10.0] - 2024/07/11

Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"homepage": "https://github.com/ditrit/terrator-plugin#readme",
"dependencies": {
"antlr4": "=4.13.1",
"leto-modelizer-plugin-core": "github:ditrit/leto-modelizer-plugin-core#0.26.1",
"leto-modelizer-plugin-core": "github:ditrit/leto-modelizer-plugin-core#0.26.2",
"nunjucks": "=3.2.4"
},
"devDependencies": {
Expand Down
23 changes: 13 additions & 10 deletions src/parser/TerraformListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class TerraformListener extends antlr4.tree.ParseTreeListener {
});
}

checkMissingAttributes(ctx) {
this.currentComponent.validateRequiredAttributes()
.forEach((error) => this.addError(ctx, error));
}

addComponent() {
this.currentComponent.path = this.currentFile.path;
this.pluginData.components.push(this.currentComponent);
Expand Down Expand Up @@ -120,7 +125,8 @@ class TerraformListener extends antlr4.tree.ParseTreeListener {
}

// Exit a parse tree produced by terraformParser#resource.
exitResource() {
exitResource(ctx) {
this.checkMissingAttributes(ctx);
this.addComponent();
}

Expand All @@ -131,7 +137,8 @@ class TerraformListener extends antlr4.tree.ParseTreeListener {
}

// Exit a parse tree produced by terraformParser#data.
exitData() {
exitData(ctx) {
this.checkMissingAttributes(ctx);
this.addComponent();
}

Expand All @@ -142,7 +149,8 @@ class TerraformListener extends antlr4.tree.ParseTreeListener {
}

// Exit a parse tree produced by terraformParser#provider.
exitProvider() {
exitProvider(ctx) {
this.checkMissingAttributes(ctx);
this.addComponent();
}

Expand Down Expand Up @@ -179,7 +187,8 @@ class TerraformListener extends antlr4.tree.ParseTreeListener {
}

// Exit a parse tree produced by terraformParser#module.
exitModule() {
exitModule(ctx) {
this.checkMissingAttributes(ctx);
this.addComponent();
}

Expand Down Expand Up @@ -552,12 +561,6 @@ class TerraformListener extends antlr4.tree.ParseTreeListener {
this.currentField.type = type;
}

this.currentField.validateDefinitionType();
this.currentField.validateType();
this.currentField.validateRequired();
this.currentField.validateRuleMinMax();
this.currentField.validateRuleValues();
this.currentField.validateRuleRegex();
this.currentField.getErrors()
.forEach((error) => this.addError(ctx, error));
}
Expand Down
12 changes: 12 additions & 0 deletions tests/resources/js/parserError.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ const errors = [
severity: ParserLog.SEVERITY_ERROR,
initialErrorMessage: null,
}),
new ParserLog({
path: 'parserError.tf',
componentId: 'id_5',
attribute: 'region',
startLineNumber: 15,
startColumn: 1,
endLineNumber: 15,
endColumn: 32,
message: 'parser.error.required',
severity: ParserLog.SEVERITY_ERROR,
initialErrorMessage: null,
}),
];

export default errors;
2 changes: 2 additions & 0 deletions tests/resources/tf/parserError.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ resource "unknown" "test3" {}
resource "aws_lb_target_group" "" {}

blabla "test" {}

provider "aws" {}

0 comments on commit c327256

Please sign in to comment.